File: configure.ac

package info (click to toggle)
vice 3.7.1%2Bdfsg1-2
  • links: PTS
  • area: contrib
  • in suites: bookworm
  • size: 49,876 kB
  • sloc: ansic: 431,530; cpp: 35,357; sh: 9,747; makefile: 7,010; perl: 1,822; yacc: 1,197; lex: 589; sed: 184; objc: 115; xml: 36
file content (3980 lines) | stat: -rwxr-xr-x 141,314 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
dnl This file is part of VICE, the Versatile Commodore Emulator.
dnl See README for copyright notice.
dnl
dnl Process this file with GNU autoconf to produce a configure script.
dnl

dnl Set VICE version number.
dnl ONLY bump this on release, any revision in the version string indicates
dnl a development version. Don't add any strings to the version number (such
dnl as '-dev' or 'beta'), the '-r$SVNREV' revision string is the only thing we
dnl alllow after the version number.
m4_define(vice_version_major, 3)
m4_define(vice_version_minor, 7)
m4_define(vice_version_build, 1)

dnl Some people lose their shit if a version ends in .0
dnl also turns out some people lose it if it doesn't :)
m4_define(vice_version,
          ifelse(vice_version_build, 0,
                 ifelse(vice_version_label, ,
                        [vice_version_major.vice_version_minor],
                        [vice_version_major.vice_version_minor]),
                 ifelse(vice_version_label, ,
                        [vice_version_major.vice_version_minor.vice_version_build],
                        [vice_version_major.vice_version_minor.vice_version_build])))

dnl The major/minor stuff gets replaced in autogen.sh
AC_INIT([vice], [vice_version])
dnl We save the command line options here since AM_INIT_AUTOMAKE and other
dnl macros clobber $@:
cmdline_options="$@"
AC_CONFIG_SRCDIR([src/maincpu.c])
AM_INIT_AUTOMAKE([-Wno-portability foreign])

dnl Make sure autotools doesn't add '-g -O2' by default when the user's CFLAGS
dnl or CXXFLAGS are empty
dnl This has to happen before any other AC_* calls, so leave it here please.
: ${CFLAGS=""}
: ${CXXFLAGS=""}
: ${OBJCFLAGS=""}

dnl Set VICE's compiler flags (can be overridden by the user)
VICE_CPPFLAGS="-I\$(top_srcdir)/src/arch/systemheaderoverride"
VICE_CFLAGS="-g -O3"
VICE_CXXFLAGS="-g -O3"
VICE_OBJCFLAGS="-g -O3"
VICE_LDFLAGS=""

dnl Avoid "ar: `u' modifier ignored since `D' is the default (see `U')" warning
dnl caused by a longstanding bug in libtool.
dnl See https://github.com/rsyslog/rsyslog/issues/1179 for some details.
: ${ARFLAGS="cr"}
: ${AR_FLAGS="cr"}
AC_SUBST(ARFLAGS)
AC_SUBST(AR_FLAGS)

AC_CONFIG_MACRO_DIR([m4])

dnl Make version number visible to generated files and source
VICE_VERSION_MAJOR=vice_version_major
VICE_VERSION_MINOR=vice_version_minor
VICE_VERSION_BUILD=vice_version_build
VICE_VERSION=vice_version
VERSION_RC="$VICE_VERSION_MAJOR,$VICE_VERSION_MINOR,$VICE_VERSION_BUILD,0"
VERSION_COMBINED=`expr $VICE_VERSION_MAJOR \* 65536 + $VICE_VERSION_MINOR \* 256 + $VICE_VERSION_BUILD`
AC_SUBST(VICE_VERSION_MAJOR)
AC_SUBST(VICE_VERSION_MINOR)
AC_SUBST(VICE_VERSION_BUILD)
AC_SUBST(VICE_VERSION)
AC_SUBST(VERSION_RC)
AC_SUBST(VERSION_COMBINED)


dnl Command-line options
dnl
dnl The whitespace (2 spaces) before --with[out]-option is significant, as is
dnl the whitespace before the option description, in order to align these
dnl properly with the auto-generated options of configure.ac
VICE_ARG_INIT()

dnl
dnl Sound options
dnl
VICE_ARG_WITH_LIST(alsa,                [  --without-alsa          do not use the ALSA sound system])
VICE_ARG_WITH_LIST(fastsid,             [  --with-fastsid          use the FastSID engine])
VICE_ARG_WITH_LIST(flac,                [  --with-flac             use FLAC support])
VICE_ARG_WITH_LIST(mpg123,              [  --with-mpg123           use MPG123 support])
VICE_ARG_WITH_LIST(oss,                 [  --with-oss              use the OSS sound system])
VICE_ARG_WITH_LIST(pulse,               [  --without-pulse         do not use PulseAudio sound system])
VICE_ARG_WITH_LIST(resid,               [  --without-resid         do not use the reSID engine])
VICE_ARG_WITH_LIST(sdlsound,            [  --with-sdlsound         use SDL sound system])
VICE_ARG_WITH_LIST(sun,                 [  --without-sun           do not use the sun/netbsd sound system])
VICE_ARG_WITH_LIST(vorbis,              [  --with-vorbis           use Ogg/Vorbis support])
VICE_ARG_ENABLE_LIST(catweasel,         [  --enable-catweasel      enables CatWeasel (PCI/Zorro/Clockport SID card) support])
VICE_ARG_ENABLE_LIST(hardsid,           [  --disable-hardsid       disables HardSID support])
VICE_ARG_ENABLE_LIST(lame,              [  --enable-lame           Enable MP3 export with LAME])
VICE_ARG_ENABLE_LIST(midi,              [  --enable-midi           enable MIDI support])
VICE_ARG_ENABLE_LIST(new8580filter,     [  --disable-new8580filter disable new 8580 filters])
VICE_ARG_ENABLE_LIST(parsid,            [  --enable-parsid         enables ParSID support])
VICE_ARG_ENABLE_LIST(portaudio,         [  --disable-portaudio     disables PortAudio support])
VICE_ARG_ENABLE_LIST(ssi2001,           [  --enable-ssi2001        enables SSI2001 (ISA SID card) support])
VICE_ARG_ENABLE_LIST(static-lame,       [  --enable-static-lame    enable static LAME linking])


dnl
dnl Graphics options
dnl
VICE_ARG_WITH_LIST(gif,                 [  --with-gif              use GIF screenshot system])
VICE_ARG_WITH_LIST(png,                 [  --without-png           do not use the PNG screenshot system])
VICE_ARG_ENABLE_LIST(ffmpeg,            [  --enable-ffmpeg         enable FFmpeg support])
dnl Only supported for SDL1
VICE_ARG_ENABLE_LIST(hwscale,           [  --disable-hwscale       disables GPU scaling of emulated screen (SDL1 UI only)])


dnl
dnl Misc build options
dnl

VICE_ARG_WITH_LIST(readline,            [  --without-readline      do not try to use the system readline library])
VICE_ARG_WITH_LIST(zlib,                [  --without-zlib          do not use the zlib support])
VICE_ARG_ENABLE_LIST(arch,              [  --enable-arch[[=arch]]    enable architecture specific compilation [[default=yes]]], [], [enable_arch=yes])
VICE_ARG_ENABLE_LIST(cpuhistory,        [  --disable-cpuhistory    disable the 65xx cpu history feature])
VICE_ARG_ENABLE_LIST(ethernet,          [  --enable-ethernet       enables The Final Ethernet emulation])
VICE_ARG_ENABLE_LIST(ipv6,              [  --disable-ipv6          disables the checking for IPv6 compatibility])
VICE_ARG_ENABLE_LIST(libieee1284,       [  --enable-libieee1284    enables libieee1284 support])
VICE_ARG_ENABLE_LIST(no-pic,            [  --enable-no-pic         enable the use of the no-pic switch [[default=yes]]])
VICE_ARG_ENABLE_LIST(realdevice,        [  --disable-realdevice    disables access to real peripheral devices (CBM4Linux/OpenCBM)])
VICE_ARG_ENABLE_LIST(rs232,             [  --disable-rs232         disable RS232 support])
VICE_ARG_ENABLE_LIST(openmp,            [  --disable-openmp        disable OpenMP acceleration])

dnl
dnl Developer options
dnl
VICE_ARG_ENABLE_LIST(cmake,             [  --enable-cmake          enable generation of CMakeLists.txt files [[default=no]]])
VICE_ARG_ENABLE_LIST(debug,             [  --enable-debug          enable debug source options])
VICE_ARG_ENABLE_LIST(debug-gtk3ui,      [  --enable-debug-gtk3ui   enables debugging for the GTK3 UI])
VICE_ARG_ENABLE_LIST(debug-threads,     [  --enable-debug-threads  enable debug messages about the threading code [[default=no]]])
VICE_ARG_ENABLE_LIST(x64,               [  --enable-x64            enable building of the old x64 emulator [[default=no]]])
VICE_ARG_ENABLE_LIST(x64-image,         [  --enable-x64-image      enable X64 image support [[default=no]]])
VICE_ARG_ENABLE_LIST(optimization,      [  --disable-optimization  disable code optimization by passing -O0 [[default=no]]])
VICE_ARG_ENABLE_LIST(extra-warnings,    [  --enable-extra-warnings enable anal warnings [[default=no]]])
VICE_ARG_ENABLE_LIST(io-simulation,     [  --enable-io-simulation  enable i/o simulation devices [[default=no]]])

dnl Temporary for something mysterious
VICE_ARG_WITH_LIST(libcurl,             [  --with-libcurl          enable libcurl support [[default=no]]])

dnl
dnl UI options
dnl
VICE_ARG_ENABLE_LIST(headlessui,        [  --enable-headlessui     enables building without a UI])
VICE_ARG_ENABLE_LIST(sdl1ui,            [  --enable-sdl1ui         enables SDL 1.2 UI support])
VICE_ARG_ENABLE_LIST(sdl2ui,            [  --enable-sdl2ui         enables SDL 2.x UI support])
VICE_ARG_ENABLE_LIST(gtk3ui,            [  --enable-gtk3ui         enables GTK3 UI support])

dnl If enabled, tries to install XDG .desktop files for running the binaries
dnl from a desktop menu. Only supported for Unix with the exception of MacOS.
dnl Gtk3 only.
VICE_ARG_ENABLE_LIST(desktop-files,     [  --enable-desktop-files  enable installation of XDG desktop files (GTK3 UI only)])
VICE_ARG_ENABLE_LIST(hidmgr,            [  --disable-hidmgr        disable IOHIDManager joystick support on Mac])

dnl
dnl Documentation options
dnl
VICE_ARG_ENABLE_LIST(html-docs,         [  --disable-html-docs     do not generate the HTML documentation [[default=no]]])
VICE_ARG_ENABLE_LIST(pdf-docs,          [  --enable-pdf-docs       generate the PDF documentation [[default=if possible]]])
VICE_ARG_ENABLE_LIST(platformdox,       [  --enable-platformdox    enable generating of documentation specific to the current host])



dnl
dnl Check for disabling compiler optimization with --disable-optimization
dnl
if test x"$enable_optimization" = "xno"; then
  VICE_CFLAGS="-g -O0"
  VICE_CXXFLAGS="-g -O0"
  VICE_OBJCFLAGS="-g -O0"
fi


AC_ARG_VAR(FW_DIR, [Location of support frameworks (macOS only)])


dnl check for conflicting options
VICE_ARG_LIST_AT_MOST_ONE([--enable-sdlui --enable-sdlui2 --enable-gtk3ui --enable-headlessui], [UI])
AS_IF([test x"$enable_gtk3ui" = "xno" -a x"$enable_sdl1ui" = "xno" -a x"$enable_sdl2ui" = "xno" -a x"$enable_headlessui" = "xno"],
      [AC_MSG_ERROR([You cannot disable all GUIs])])

dnl Try to find out which system we are on...
AC_CANONICAL_HOST

dnl Check for the existence of various programs that VICE and its component systems use

dnl Find compiler
AC_PROG_CC([cc gcc clang])

dnl Make sure the compiler supports C99 at a minimum
AC_PROG_CC_C99
AS_IF([test x"$ac_cv_prog_cc_c99" = "xno"],
      [AC_MSG_ERROR([A C99-compliant compiler is required.])])
dnl Force C99-compliance
dnl     Currently breaks some code depending on POSIX/BSD functions, for that
dnl     we'll have to pass -D_BSD_SOURCE or a similar define to the compiler,
dnl     before #including any header. So for now this is disabled.
dnl VICE_CFLAGS="$VICE_CFLAGS -std=c99"
AC_PROG_CPP
dnl C++ check, at least C++11
AC_PROG_CXX([c++ g++ clang++])
AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory])
AC_PROG_CXXCPP
AC_PROG_OBJC([cc gcc clang])

dnl Try global compiler warnings
dnl
dnl Temporarily removed:
dnl     -Wextra (enables -Wsign-compare)
dnl     -Wswitch-default
dnl     -Wswitch-enum
dnl     -Wconversion
dnl     -Wredundant-decls
dnl     -Wnested-externs
dnl     -Wcast-qual
dnl     -Wcast-align
dnl     -Wsign-compare
dnl
dnl (Commenting these out in the following list makes configure barf)
dnl
dnl NOTE - before you optimise away the weird SUCCESS_CFLAGS thing, understand the following:
dnl        clang doesn't exit with an error for an unsupported warning flag by default.
dnl        clang has -Werror=x to promote a warning to an error, but gcc treats that as an error
dnl        clang and gcc both support -Werror to promote all warnings to errors
dnl        initialising and returning the value of arse removes the gcc warning that arse isn't used.
dnl        So, until a better solution is found, -Werror is added while testing -W flag support.
dnl
dnl Warnings added to C should also be added to C++ compiler list. Except these ones because novte:
dnl     -Wstrict-prototypes (g++ warning: "cc1plus: -Wstrict-prototypes is only valid of C/ObjC not C++" - but zero exit code)
dnl     -Wformat-signedness         (novte warnings - these could be addressed with source changes)
dnl
dnl C++ warnings implied by other settings but explicitly disabled:
dnl     -Waddress-of-packed-member  (novte warnings)
dnl     -Wchar-subscripts           (novte warnings)
dnl
dnl -Wunused-but-set-variable is enabled by -Wall in GCC >= 4.6 but doesn't
dnl exist in clang < 13.0. clang-tidy implements this check though, so our
dnl Github code analysis runner should find these issues pre-clang 13.
dnl
m4_foreach([flag],
           [[-W],
            [-Wall],
            [-Wextra],
            [-Wformat],
            [-Wformat-signedness],
            [-Wformat-pedantic],
            [-Wformat-security],
            [-Wshadow],
            [-Wpointer-arith],
            [-Wmissing-prototypes],
            [-Wstrict-prototypes],
            [-Wuninitialized],
            [-Wunreachable-code],
            [-Wmacro-redefined],
            [-Werror=implicit-function-declaration],
            [-Wfatal-errors],
            [-fdiagnostics-absolute-paths],
            [-Wshorten-64-to-32],
            [-Wdiscarded-qualifiers],
            [-Wno-unknown-pragmas],
            [-Wunused-but-set-variable]],
           [TEST_FLAG=flag
            VICE_CFLAG_REQUEST([$TEST_FLAG])
           ])

dnl Disable extra warnings if requested
dnl
dnl Enabled by default, disable with `--disable-extra-warnings`
if test x"$enable_extra_warnings" != "xyes"; then
    m4_foreach([flag],
               [[-Wno-sign-compare],
                [-Wno-missing-field-initializers],
                [-Wno-ignored-qualifiers],
                [-Wno-unused-parameter]],
               [TEST_FLAG=flag
                VICE_CFLAG_REQUEST([$TEST_FLAG])
               ])
fi


dnl Check C++ flags
m4_foreach([flag],
           [[-Wall],
            [-Wformat],
            [-Wformat-pedantic],
            [-Wshadow],
            [-Wpointer-arith],
            [-Wuninitialized],
            [-Wunreachable-code],
            [-Wno-unused-parameter],
            [-Wmissing-prototypes],
            [-Werror=implicit-function-declaration],
            [-Wfatal-errors],
            [-fdiagnostics-absolute-paths],
            [-Wshorten-64-to-32]],
           [TEST_FLAG=flag
            VICE_CXXFLAG_REQUEST([$TEST_FLAG])
           ])

dnl VTE specific C++ flags
VTE_CXXFLAGS=""
m4_foreach([flag],
           [[-Wno-address-of-packed-member],
            [-Wno-char-subscripts],
            [-Wno-format-signedness],
            [-Wno-missing-prototypes],
            [-Wno-c99-designator],
            [-Wno-shorten-64-to-32],
            [-Wno-nonnull-compare]],
           [TEST_FLAG=flag
            VICE_CXXFLAG_REQUEST([$TEST_FLAG], [VTE_CXXFLAGS])
            ])
AC_SUBST(VTE_CXXFLAGS)

dnl Monitor specific flags (due to the code generated by yacc/lex)
MONITOR_CFLAGS=""
m4_foreach([flag],
           [[-Wno-unused-label],
            [-Wno-unreachable-code],
            [-Wno-misleading-indentation]],
           [TEST_FLAG=flag
            VICE_CFLAG_REQUEST([$TEST_FLAG], [MONITOR_CFLAGS])
            ])
AC_SUBST(MONITOR_CFLAGS)

AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_LEX
AS_IF([test x"$LEX" = "x:"], [AC_MSG_ERROR([Could not find either flex or lex!])])

AC_LIB_PROG_LD

AC_CHECK_PROG(AR, ar, ar, ar)
AC_CHECK_PROG(SVN, svn, svn, :)
AC_CHECK_PROG(TAR, tar, tar, :)
AC_CHECK_PROG(SVNVERSION, svnversion, svnversion, :)
AC_CHECK_PROGS(YACC, byacc yacc 'bison -y', [no])
AS_IF([test x"$YACC" = "xno"], [AC_MSG_ERROR([Could not find byacc, yacc or bison!])])

dnl Check for makeinfo, might only be required for AmigaOS since we don't
dnl generate info pages anymore ?
AC_CHECK_PROGS(MAKEINFO, makeinfo, no)
AS_IF([test x"$MAKEINFO" = "xno"],
      [AC_MSG_ERROR([makeinfo is missing, please install texinfo])])

dnl Check for dos2unix
AC_CHECK_PROGS(DOS2UNIX, dos2unix, no)
AS_IF([test x"$DOS2UNIX" = "xno"],
      [AC_MSG_ERROR([The dos2unix tool is missing, please install dos2unix])])

dnl Check for xa[65]
AC_CHECK_PROGS(XA, [xa xa65], no)
AS_IF([test x"$XA" = "xno"],
      [AC_MSG_ERROR([The xa assembler is missing, either install it via your
                  distribution or build and install it using the latest source
                  from https://www.floodgap.com/retrotech/xa/])])

if test x"$enable_pdf_docs" != xno; then
  AC_CHECK_PROGS(TEXI2DVI, texi2dvi, no)
  if test x"$TEXI2DVI" = "xno"; then
    AC_MSG_ERROR([PDF docs were requested (--enable-pdf-docs), but texi2dvi is missing])
  fi
  AC_CHECK_PROGS(PDFTEX, pdftex, no)
  if test x"$PDFTEX" = "xno"; then
    AC_MSG_ERROR([PDF docs were requested (--enable-pdf-docs), but pdftex is missing])
  fi

fi

AC_CHECK_PROGS(PERL, perl)

if test x"${enable_html_docs:-yes}" != xno -a x"$PERL" = x; then
  AC_MSG_ERROR([Perl is required to generate the HTML documentation])]
fi

AM_CONDITIONAL([ENABLE_PDF_DOCS], [test x"${enable_pdf_docs}" != xno])
if test x"${enable_pdf_docs}" != "xno"; then
    VICE_PDF_FILE_NAME="vice.pdf"
else
    VICE_PDF_FILE_NAME=""
fi
AC_SUBST(VICE_PDF_FILE_NAME)

AM_CONDITIONAL([ENABLE_HTML_DOCS], [test x"${enable_html_docs:-yes}" != xno])
AM_CONDITIONAL([HAVE_PERL], [test x"$PERL" != x])

AC_CHECK_PROGS(ICONV, iconv, no)
AS_IF([test x"$ICONV" = x"no"], [AC_MSG_ERROR([iconv is missing])])
AC_CHECK_TOOL(RANLIB, ranlib, :)
AC_CHECK_TOOL(STRIP, strip, :)
AC_CHECK_TOOL(objdump, objdump, no)
AC_CHECK_TOOL(sdl_config, sdl-config, no)

dnl echo "Checking host_os for Windows: host_os = $host_os"
dnl Check for windres, required to link icons into windows binaries
if test x"$host_os" = "xmingw32"; then
    AC_CHECK_TOOL([WINDRES], [windres], [no])
    AS_IF([test x"$WINDRES" = "xno"],
           [AC_MSG_ERROR([Could not find required windres binary!])])
fi


AM_PROG_AS

dnl Other build environment checks
AC_SYS_LARGEFILE

AC_CONFIG_HEADERS([src/config.h])


is_unix=no
is_unix_x11=no
is_unix_macosx=no
is_win32=no
is_win32_gtk3=no
is_beos=no


BSD_JOYSTICK_SUPPORT="no "
DEBUG_SUPPORT="no "
DEBUG_THREADS_SUPPORT="no "
FEATURE_CPUMEMHISTORY_SUPPORT="no "
HAS_HIDMGR_SUPPORT="no "
HAS_USB_JOYSTICK_SUPPORT="no "
HAVE_AUDIO_UNIT_SUPPORT="no "
HAVE_CATWEASELMKIII_SUPPORT="no "
HAVE_DINPUT_SUPPORT="no "
HAVE_DYNLIB_SUPPORT_TOO="no "
HAVE_FASTSID_SUPPORT="no "
HAVE_FFMPEG_AVRESAMPLE_SUPPORT="no "
HAVE_FFMPEG_SUPPORT="no "
HAVE_FFMPEG_SWRESAMPLE_SUPPORT="no "
HAVE_FFMPEG_SWSCALE_SUPPORT="no "
HAVE_FONTCONFIG_SUPPORT="no "
HAVE_GIF_SUPPORT="no "
HAVE_HARDSID_SUPPORT="no "
HAVE_HWSCALE_SUPPORT="no "
HAVE_IOSID_SUPPORT="no "
HAVE_IPV6_SUPPORT="no "
HAVE_LIBIEEE1284_SUPPORT="no "
HAVE_LIGHTPEN_SUPPORT="no "
HAVE_MIDI_SUPPORT="no "
HAVE_MOUSE_SUPPORT="no "
HAVE_NETWORK_SUPPORT="no "
HAVE_PARSID_SUPPORT="no "
HAVE_PCIUTILS_SUPPORT="no "
HAVE_PNG_SUPPORT="no "
HAVE_PORTSID_SUPPORT="no "
HAVE_RAWNET_SUPPORT="no "
HAVE_REALDEVICE_SUPPORT="no "
HAVE_RESID_SUPPORT="no "
HAVE_RS232DEV_SUPPORT="no "
HAVE_RS232NET_SUPPORT="no "
HAVE_OPENMP_SUPPORT="no "
HAVE_SDL_NUMJOYSTICKS_SUPPORT="no "
HAVE_SSI2001_SUPPORT="no "
HAVE_SYS_AUDIOIO_H_SUPPORT="no "
HAVE_SYS_AUDIO_H_SUPPORT="no "
HAVE_ZLIB_SUPPORT="no "
LINUX_JOYSTICK_SUPPORT="no "
MAC_JOYSTICK_SUPPORT="no "
USE_ALSA_SUPPORT="no "
USE_COREAUDIO_SUPPORT="no "
USE_DMEDIA_SUPPORT="no "
USE_DXSOUND_SUPPORT="no "
USE_FLAC_SUPPORT="no "
USE_LAMEMP3_SUPPORT="no "
USE_MPG123_SUPPORT="no "
USE_OSS_SUPPORT="no "
USE_PORTAUDIO_SUPPORT="no "
USE_PULSE_SUPPORT="no "
USE_SANDBOX_MODE="no "
USE_SDL_AUDIO_SUPPORT="no "
USE_VORBIS_SUPPORT="no "
USE_NEW_8580_FILTER="no "
USE_DESKTOP_FILES="no "
HAVE_X64_IMAGE_SUPPORT="no "
HAVE_CAPABILITIES_SUPPORT="no "
HAVE_LIBCURL_SUPPORT="no "


dnl Why do we have this?
AM_CONDITIONAL(DUMMY_COMPILE, false)

dnl Set all FOO_COMPILE conditionals to false to simplify the code below

dnl BEOS_COMPILE means both 'classic' BeOS and Haiku
AM_CONDITIONAL(BEOS_COMPILE, false)
dnl HAIKU_COMPILE means specifically Haiku
AM_CONDITIONAL(HAIKU_COMPILE, false)
AM_CONDITIONAL(LINUX_COMPILE, false)
dnl BSD_COMPILE means Free, Net, Open and DragonFly BSD
AM_CONDITIONAL(BSD_COMPILE, false)
AM_CONDITIONAL(FREEBSD_COMPILE, false)
AM_CONDITIONAL(NETBSD_COMPILE, false)
AM_CONDITIONAL(OPENBSD_COMPILE, false)
AM_CONDITIONAL(DRAGONFLYBSD_COMPILE, false)


AS_IF([test x"$enable_cpuhistory" != "xno"],
  [
    AC_DEFINE(FEATURE_CPUMEMHISTORY,,[Use the 65xx cpu history feature.])
    FEATURE_CPUMEMHISTORY_SUPPORT="yes"
  ])

dnl New 8580 filters: Changed on 2020-08-23 from default 'no' to default 'yes'.
dnl If we don't get any (valid) complaints, we should make this non-configurable.
AS_IF([test x"$enable_new8580filter" != "xno"],
  [
    AC_DEFINE(HAVE_NEW_8580_FILTER,,[Use the new 8580 filter])
    USE_NEW_8580_FILTER="yes"
  ])

AM_CONDITIONAL(VICE_QUIET, test x"$verbose" != "xyes" -a x"$enable_silent_rules" = "x")

user_cflags=$CFLAGS

PKG_PROG_PKG_CONFIG

SOUND_DRIVERS=""

dnl Check if a GUI order check needs to be done
AS_IF([test x"$enable_gtk3ui" != "xyes" -a x"$enable_sdl1ui" != "xyes" -a x"$enable_sdl2ui" != "xyes" -a x"$enable_headlessui" != "xyes"],
      [check_guis=yes])

dnl Check if gtk3 ui should be checked
if test x"$check_guis" = "xyes"; then
  if test x"$enable_gtk3ui" != "xno"; then
    check_gtk3=yes
  fi
else
  if test x"$enable_gtk3ui" = "xyes"; then
    check_gtk3=yes
  fi
fi


old_CFLAGS="$CFLAGS"
CFLAGS="$VICE_CFLAGS"
dnl Do these checks before any Gtk3 flags are added
AC_MSG_CHECKING(for time_t in time.h)
AC_CACHE_VAL(bu_cv_decl_time_t_time_h,
[AC_TRY_COMPILE([#include <time.h>], [time_t i;],
bu_cv_decl_time_t_time_h=yes, bu_cv_decl_time_t_time_h=no)])
AC_MSG_RESULT($bu_cv_decl_time_t_time_h)
if test $bu_cv_decl_time_t_time_h = yes; then
  AC_DEFINE([HAVE_TIME_T_IN_TIME_H],,
            [Is the type time_t defined in <time.h>?])
fi

AC_MSG_CHECKING(for time_t in sys/types.h)
AC_CACHE_VAL(bu_cv_decl_time_t_types_h,
[AC_TRY_COMPILE([#include <sys/types.h>], [time_t i;],
bu_cv_decl_time_t_types_h=yes, bu_cv_decl_time_t_types_h=no)])
AC_MSG_RESULT($bu_cv_decl_time_t_types_h)
if test $bu_cv_decl_time_t_types_h = yes; then
  AC_DEFINE([HAVE_TIME_T_IN_TYPES_H],,
            [Is the type time_t defined in <sys/types.h>?])
fi

if test $bu_cv_decl_time_t_time_h = yes; then
  AC_CHECK_SIZEOF([time_t],[],[#include <time.h>])
else
  AC_CHECK_SIZEOF([time_t],[],[#include <sys/types.h>])
fi

if test "x$ac_cv_sizeof_time_t" = "x4"; then
  AC_DEFINE([TIME_T_IS_32BIT],,[time_t is 32 bit])
elif test "x$ac_cv_sizeof_time_t" = "x8"; then
  AC_DEFINE([TIME_T_IS_64BIT],,[time_t is 64 bit])
else
  AC_MSG_ERROR([can not figure type of time_t])
fi


dnl Add runtime/linker paths for *BSD
CFLAGS="$old_CFLAGS"

case "$host_os" in
  freebsd*)
    AC_DEFINE(BSD_COMPILE,,[Are we compiling for *BSD?])
    AC_DEFINE(FREEBSD_COMPILE,,[Are we compiling for FreeBSD?])
    AM_CONDITIONAL(BSD_COMPILE, true)
    AM_CONDITIONAL(FREEBSD_COMPILE, true)
    CPPFLAGS="$CPPFLAGS -I/usr/local/include"
    fbsdrtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$VICE_LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/local/lib"`
    VICE_LDFLAGS="$VICE_LDFLAGS $fbsdrtp -L/usr/local/lib"
    ;;
  netbsd*)
    AC_DEFINE(BSD_COMPILE,,[Are we compiling for *BSD?])
    AC_DEFINE(NETBSD_COMPILE,,[Are we compiling for NetBSD?])
    AM_CONDITIONAL(BSD_COMPILE, true)
    AM_CONDITIONAL(NETBSD_COMPILE, true)
    CPPFLAGS="$CPPFLAGS -I/usr/pkg/include -I/usr/include"
    nbsdrtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$VICE_LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/pkg/lib"`
    VICE_LDFLAGS="$VICE_LDFLAGS $nbsdrtp -L/usr/pkg/lib"
    if test -d "/usr/X11R7/lib"; then
      CPPFLAGS="$CPPFLAGS -I/usr/X11R7/include"
      rtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$VICE_LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/X11R7/lib"`
      VICE_LDFLAGS="$VICE_LDFLAGS $rtp"
      LDFLAGS="$LDFLAGS -L/usr/X11R7/lib"
    else
      if test -d "/usr/X11R6/lib"; then
        CPPFLAGS="$CPPFLAGS -I/usr/X11R6/include"
        rtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$VICE_LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/X11R6/lib"`
        VICE_LDFLAGS="$VICE_LDFLAGS $rtp -L/usr/X11R6/lib"
        LDFLAGS="$LDFLAGS -L/usr/X11R6/lib"
      fi
    fi
    ;;
  openbsd*)
    AC_DEFINE(BSD_COMPILE,,[Are we compiling for *BSD?])
    AC_DEFINE(OPENBSD_COMPILE,,[Are we compiling for OpenBSD?])
    AM_CONDITIONAL(BSD_COMPILE, true)
    AM_CONDITIONAL(OPENBSD_COMPILE, true)
    CPPFLAGS="$CPPFLAGS -I/usr/local/include"
    obsdrtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$VICE_LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/local/lib"`
    VICE_LDFLAGS="$VICE_LDFLAGS $obsdrtp -L/usr/local/lib"
    ;;
  dragonfly*)
    AC_DEFINE(BSD_COMPILE,,[Are we compiling for *BSD?])
    AC_DEFINE(DRAGONFLYBSD_COMPILE,,[Are we compiling for DragonFly BSD?])
    AM_CONDITIONAL(BSD_COMPILE, true)
    AM_CONDITIONAL(DRAGONFLYBSD_COMPILE, true)
    CPPFLAGS="$CPPFLAGS -I/usr/local/include"
    dfbsdrtp=`${CONFIG_SHELL-/bin/sh} "$srcdir/config.rpath" "$CC" "$GCC" "$VICE_LDFLAGS" "$LD" "$with_gnu_ld" "$host" "/usr/local/lib"`
    VICE_LDFLAGS="$VICE_LDFLAGS $dfbsdrtp -L/usr/local/lib"
    ;;
  dnl Why is this in BSD section?
  cygwin*)
    VICE_CPPFLAGS="$VICE_CPPFLAGS -D_GNU_SOURCE=1"
    ;;
  dnl Again: why?
  mingw32*)
    is_win32=yes
    ;;
  *)
    ;;
esac


if test "x$CC" = "xgcc"; then
  GCC=yes
fi


if test x"$enable_arch" = "xno"; then
  march=""
  ENABLE_ARCH=no
else
  if test x"$enable_arch" = "xyes"; then
    AC_MSG_CHECKING([if the compiler supports -march=native])
    ORIG_CFLAGS="$VICE_CFLAGS"
    VICE_CFLAGS="$VICE_CFLAGS -march=native"
    AC_TRY_COMPILE([],
                   [int test;],
                   [ AC_MSG_RESULT(yes)
                     ENABLE_ARCH=yes
                     march="-march=native" ],
                   [ AC_MSG_RESULT(no)
                     ENABLE_ARCH=no
                     march="" ])
    VICE_CFLAGS="$ORIG_CFLAGS"
  else
    AC_MSG_CHECKING([if the compiler supports -march=$enable_arch])
    ORIG_CFLAGS="$VICE_CFLAGS"
    VICE_CFLAGS="$VICE_CFLAGS -march=$enable_arch"
    AC_TRY_COMPILE([],
                   [int test;],
                   [ AC_MSG_RESULT(yes)
                     ENABLE_ARCH=yes
                     march="-march=$enable_arch" ],
                   [ AC_MSG_RESULT(no)
                     ENABLE_ARCH=no
                     march="" ])
    VICE_CFLAGS="$ORIG_CFLAGS"
  fi
fi

AC_SUBST(ENABLE_ARCH)

dnl check if the compiler supports -posix
if test x"$posix_check" = "xyes"; then
  AC_MSG_CHECKING([if the compiler supports -posix])
  ORIG_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS -posix"
  AC_TRY_COMPILE([],
                 [int test;],
                 [ AC_MSG_RESULT(yes)],
                 [ AC_MSG_RESULT(no)
                   CFLAGS=$ORIG_CFLAGS ])
fi

dnl check if ar truncates object names
if test x"$ar_check" != "xno"; then
  AC_MSG_CHECKING(if ar truncates object names)
  rm -f vicetest.c
  touch vicetest.c
  $CC -c vicetest.c -o some_long_object_name.o
  rm -f vicetest.c
  rm -f libvicetest.a
  $AR cru libvicetest.a some_long_object_name.o
  rm -f some_long_object_name.o
  $AR x libvicetest.a
  if test -f some_long_object_name.o; then
    AC_MSG_RESULT(no)
    rm -f some_long_object_name.o libvicetest.a
  else
    AC_MSG_RESULT(yes)
    rm -f some*.o libvicetest.a
    AC_MSG_ERROR([ar is too old, upgrade your ar])
  fi
fi


AM_CONDITIONAL(USE_SVN_REVISION,false)
AM_CONDITIONAL(USE_SVN_REVISION_OVERRIDE,false)

AC_ARG_VAR(SVN_REVISION_OVERRIDE,,[Subversion revision number to embed in build (without the 'r')])

if test x"$SVN_REVISION_OVERRIDE" != "x"; then
  AM_CONDITIONAL(USE_SVN_REVISION,true)
  AM_CONDITIONAL(USE_SVN_REVISION_OVERRIDE,true)
  AC_DEFINE(USE_SVN_REVISION,,[define when using the svn revision in addition to the version])
  AC_DEFINE(USE_SVN_REVISION_OVERRIDE,,[define when using an svn revision passed to configure via SVN_REVISION_OVERRIDE env var])
else
  if test x"$SVN" != "x"; then
    svnrevision=`$SVN 2>dummy.tmp info $srcdir | grep Revision | cut -d " " -f 2`
    rm dummy.tmp
    if test x"$svnrevision" != "x"; then
      AC_DEFINE(USE_SVN_REVISION,,[define when using the svn revision in addition to the version])
      AM_CONDITIONAL(USE_SVN_REVISION,true)
    fi
  fi
fi

JOYSTICK_DRIVERS=""

dnl Hardware SID drivers (obsolete so disabled by default)
AM_CONDITIONAL(HAVE_CATWEASELMKIII, false)
AM_CONDITIONAL(HAVE_PARSID, false)
AM_CONDITIONAL(HAVE_SSI2001, false)

if test x"$is_win32" = "xyes" -o x"$is_win32_gtk3" = "xyes"; then

  dnl This is used by subsequent tests.
  ac_cv_prog_gcc=yes
  GCC=yes

  AC_CHECK_HEADERS([commctrl.h shlobj.h winioctl.h], [], [], [#include <windows.h>])

  AC_DEFINE(HAVE_HTONL,,[Define to 1 if you have the htonl function.])
  AC_DEFINE(HAVE_HTONS,,[Define to 1 if you have the htons function.])
  AC_DEFINE(HAVE_NETWORK,,[Enable netplay support])
  HAVE_NETWORK_SUPPORT="yes"
  AC_DEFINE(HAVE_RS232NET,,[Enable RS232 network support])
  HAVE_RS232NET_SUPPORT="yes"
  if test x"$host_cpu" = "xx86_64" -o x"$host_cpu" = "xamd64"; then
    LIBS="$LIBS -lwinmm -lntdll -ld2d1 -ld3d11 -lavrt -lws2_32"
  else
    LIBS="$LIBS -lwinmm -lntdll -ld2d1 -ld3d11 -lavrt -lwsock32 -lmingwex -lmsvcrt"
  fi
  if test x"$enable_catweasel" = "xyes"; then
    AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
    AM_CONDITIONAL(HAVE_CATWEASELMKIII, true)
    HAVE_CATWEASELMKIII_SUPPORT="yes"
  fi
  if test x"$enable_hardsid" != "xno"; then
    AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
    HAVE_HARDSID_SUPPORT="yes"
  fi
  if test x"$enable_parsid" = "xyes"; then
    AC_DEFINE(HAVE_PARSID,,[Support for ParSID.])
    AM_CONDITIONAL(HAVE_PARSID, true)
    HAVE_PARSID_SUPPORT="yes"

    if test x"$enable_libieee1284" = "xyes"; then
      LIBIEEE1284_HEADERS_PRESENT=yes

      dnl Check for needed io headers
      AC_CHECK_HEADERS(ieee1284.h,,[LIBIEEE1284_HEADERS_PRESENT=no],)

      if test x"$LIBIEEE1284_HEADERS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(ieee1284, ieee1284_find_ports,[LIBS="-lieee1284 $LIBS"; PARSID_SUPPORT=yes],,)
        if test x"$PARSID_SUPPORT" = "xyes"; then
          AC_DEFINE(HAVE_LIBIEEE1284,,[Define to 1 if you have the 'ieee1284' library (-lieee1284).])
        else
          AC_MSG_ERROR([libieee1284 is missing])
        fi
      else
        AC_MSG_ERROR([libieee1284 header is missing])
      fi
    fi
  fi
  if test x"$enable_ssi2001" = "xyes"; then
    AC_DEFINE(HAVE_SSI2001,,[Support for SSI2001 (ISA SID card).])
    AM_CONDITIONAL(HAVE_SSI2001, true)
    HAVE_SSI2001_SUPPORT="yes"
  fi
  if test x"$enable_midi" = "xyes"; then
    AC_DEFINE(HAVE_MIDI,,[Enable support for MIDI.])
    HAVE_MIDI_SUPPORT="yes"
  fi
  if test x"$enable_rs232" != "xno"; then
    AC_DEFINE(HAVE_RS232DEV,,[Enable RS232 device emulation.])
    HAVE_RS232DEV_SUPPORT="yes"
  fi

  dnl warnings_cxx="-Wall -W -Wno-unused-parameter -Wno-missing-field-initializers -Wno-sign-compare"
  dnl (Didn't we already check this?
  if test x"$nowarnings" != "xyes"; then
      warnings_cxx="-Wall -Wno-unused-parameter -Wno-sign-compare"
      VICE_CFLAGS="$VICE_CFLAGS $warnings_cxx"
      VICE_CXXFLAGS="$VICE_CXXFLAGS $warnings_cxx"
  fi

elif test x"$host_os" = "xbeos" -o x"$host_os" = "xhaiku"; then

  dnl Again: ingnored for now

  dnl This is used by subsequent tests.
  ac_cv_prog_gcc=yes
  GCC=yes

  is_beos=yes
  AC_DEFINE(BEOS_COMPILE,,[Are we compiling for either BeOS or Haiku?])
  AM_CONDITIONAL(BEOS_COMPILE, true)

  if test x"$host_os" = "xhaiku"; then
    AC_DEFINE(HAIKU_COMPILE,,[Are we compiling for Haiku?])
    AM_CONDITIONAL(HAIKU_COMPILE, true)
  fi

  if test x"$enable_catweasel" = "xyes"; then
    AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
    AM_CONDITIONAL(HAVE_CATWEASELMKIII, true)
    HAVE_CATWEASELMKIII_SUPPORT="yes"
  fi

  if test x"$enable_hardsid" != "xno"; then
    AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
    HAVE_HARDSID_SUPPORT="yes"
  fi

  if test x"$enable_parsid" = "xyes"; then
    AC_DEFINE(HAVE_PARSID,,[Support for ParSID.])
    AM_CONDITIONAL(HAVE_PARSID, true)
    HAVE_PARSID_SUPPORT="yes"

    if test x"$enable_libieee1284" = "xyes"; then
      LIBIEEE1284_HEADERS_PRESENT=yes

      dnl Check for needed io headers
      AC_CHECK_HEADERS(ieee1284.h,,[LIBIEEE1284_HEADERS_PRESENT=no],)

      if test x"$LIBIEEE1284_HEADERS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(ieee1284, ieee1284_find_ports,[LIBS="-lieee1284 $LIBS"; PARSID_SUPPORT=yes],,)
        if test x"$PARSID_SUPPORT" = "xyes"; then
          AC_DEFINE(HAVE_LIBIEEE1284,,[Define to 1 if you have the 'ieee1284' library (-lieee1284).])
        else
          AC_MSG_ERROR([libieee1284 is missing])
        fi
      else
        AC_MSG_ERROR([libieee1284 header is missing])
      fi
    fi
  fi

  if test x"$enable_ssi2001" = "xyes"; then
    AC_DEFINE(HAVE_SSI2001,,[Support for SSI2001 (ISA SID card).])
    AM_CONDITIONAL(HAVE_SSI2001, true)
    HAVE_SSI2001_SUPPORT="yes"
  fi

  dnl Haiku needs a few compiler flags to compile:
  dnl Probably can get rid off libstdc++, but who will ever notice?
  VICE_CFLAGS="$VICE_CFLAGS -static -static-libgcc -static-libstdc++"

else

dnl check for darwin first.
case "$host_os" in
darwin*)
  dnl check for needed CoreVideo header
  AC_CHECK_HEADERS(CoreVideo/CVHostTime.h)

  dnl check for needed CoreServices header
  AC_CHECK_HEADERS(CoreServices/CoreServices.h)

  dnl change the host_os to puredarwin to make the configure think it is
  dnl just another unix.
  if test x"$ac_cv_header_CoreServices_CoreServices_h" != "xyes"; then
    host_os=puredarwin;
    AC_DEFINE(DARWIN_COMPILE,,[Enable plain darwin compilation])
  fi
  ;;
*)
  ;;
esac

dnl Check for host os with version attached. Typically on UN*X like systems.
case "$host_os" in

dnl Mac OS X Host
darwin*)

  AC_PROG_OBJCPP

  is_unix=yes
  is_unix_macosx=yes
  is_unix_x11=yes

  dnl disable toolchain checking for macosx
  toolchain_check=no

  dnl The vice build system builds empty libs for things that are configured out,
  dnl then links all of them together. This causes ranlib to complain like:
  dnl
  dnl   file: libarch.a(joy-win32-dinput-handle.o) has no symbols
  dnl
  dnl This warning can be disabled by passing -no_warning_for_no_symbols to ranlib.
  dnl ar also calls ranlib, and there is no way to pass the argument.
  dnl
  dnl You can split an 'ar cru' call into separate ar and ranlib calls, but,
  dnl sometimes ranlib will invoke libtool which has its own warning we can't
  dnl change without major build system changes.
  dnl
  dnl Given all that it's simpler to just grep -v out the warnings we don't want,
  dnl which these scripts do.

  RANLIB="\$(top_srcdir)/src/arch/shared/macOS-wrap-ranlib.sh"
  AR="\$(top_srcdir)/src/arch/shared/macOS-wrap-ar.sh"

  dnl
  dnl Support targeting a specific macOS version
  dnl

  VICE_ARG_ENABLE_LIST(
    macos-minimum-version,
    AS_HELP_STRING(
      [--enable-macos-minimum-version=version],
      [compile for a specific macOS version such as 10.10 or 11.0])
    )
  if test x"$enable_macos_minimum_version" = "x"; then
    AC_MSG_CHECKING([default macOS minimum version (use --enable-macos-minimum-version to override)])
    enable_macos_minimum_version=`echo "int main(int argc, char** argv) { return 0; }" | cc -x c - ;
                                  otool -l a.out | awk '/LC_VERSION_MIN_MACOSX/ { f_old=1 }
                                                        /LC_BUILD_VERSION/ { f_new=1 }
                                                        f_old && /version/ { print $2; exit; }
                                                        f_new && /minos/ { print $2; exit; }' ;
                                  rm a.out`
    AC_MSG_RESULT($enable_macos_minimum_version)
  else
    AC_MSG_CHECKING([if the compiler supports -mmacosx-version-min=$enable_macos_minimum_version])
    ORIG_CFLAGS="$CFLAGS"
    CFLAGS="$VICE_CFLAGS -mmacosx-version-min=$enable_macos_minimum_version"
    AC_TRY_COMPILE([],
                  [int test;],
                  [ AC_MSG_RESULT(yes)
                    CFLAGS="$ORIG_CFLAGS"],
                  [ AC_MSG_RESULT(no)
                    AC_MSG_ERROR([Requested macOS minimum version $enable_macos_minimum_version not supported])
                    ])
  fi

  VICE_CFLAGS="$VICE_CFLAGS -mmacosx-version-min=$enable_macos_minimum_version"
  VICE_CXXFLAGS="$VICE_CXXFLAGS -mmacosx-version-min=$enable_macos_minimum_version"
  VICE_LDFLAGS="$VICE_LDFLAGS -mmacosx-version-min=$enable_macos_minimum_version"

  dnl
  dnl Yeah, OpenGL and other stuff is deprecated, we don't need to be warned about it.
  dnl Please don't remove this again whoever did last time :)
  dnl

  VICE_CFLAGS="$VICE_CFLAGS -Wno-deprecated-declarations"
  VICE_CXXFLAGS="$VICE_CXXFLAGS -Wno-deprecated-declarations"

  if test x"$enable_rs232" != "xno"; then
    AC_DEFINE(HAVE_RS232DEV,,[Enable RS232 device emulation.])
    HAVE_RS232DEV_SUPPORT="yes"
  fi

  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"

  AC_DEFINE(MACOS_COMPILE,,[Enable MacOS-specific code.])

  dnl Set CPPFLAGS as well as VICE_CPPFLAGS for the macports / homebrew dep search paths.
  dnl If we don't, then various header / compile checks won't succeed.

  MAC_CCPFLAGS=""
  MAC_LDFLAGS="-headerpad_max_install_names"
  MAC_FRAMEWORKS="-framework CoreText -framework CoreServices -framework AppKit -framework CoreGraphics"

  dnl Macports headers and libraries

  AC_CHECK_FILE(/opt/local/include,         [ MAC_CCPFLAGS="$MAC_CCPFLAGS -I/opt/local/include" ])
  AC_CHECK_FILE(/opt/local/include/libomp,  [ MAC_CCPFLAGS="$MAC_CCPFLAGS -I/opt/local/include/libomp" ])
  AC_CHECK_FILE(/opt/local/lib,             [ MAC_LDFLAGS="$MAC_LDFLAGS -L/opt/local/lib -Wl,-rpath,/opt/local/lib" ])
  AC_CHECK_FILE(/opt/local/lib/libomp,      [ MAC_LDFLAGS="$MAC_LDFLAGS -L/opt/local/lib/libomp -Wl,-rpath,/opt/local/lib/libomp" ])

  dnl Homebrew headers and libraries

  if test "`uname -m`" = "arm64"; then
    AC_CHECK_FILE(/opt/homebrew/include,         [ MAC_CCPFLAGS="$MAC_CCPFLAGS -I/opt/homebrew/include" ])
    AC_CHECK_FILE(/opt/homebrew/include/libomp,  [ MAC_CCPFLAGS="$MAC_CCPFLAGS -I/opt/homebrew/include/libomp" ])
    AC_CHECK_FILE(/opt/homebrew/lib,             [ MAC_LDFLAGS="$MAC_LDFLAGS -L/opt/homebrew/lib -Wl,-rpath,/opt/homebrew/lib" ])
    AC_CHECK_FILE(/opt/homebrew/lib/libomp,      [ MAC_LDFLAGS="$MAC_LDFLAGS -L/opt/homebrew/lib/libomp -Wl,-rpath,/opt/homebrew/lib/libomp" ])
  else
    AC_CHECK_FILE(/usr/local/include,         [ MAC_CCPFLAGS="$MAC_CCPFLAGS -I/usr/local/include" ])
    AC_CHECK_FILE(/usr/local/include/libomp,  [ MAC_CCPFLAGS="$MAC_CCPFLAGS -I/usr/local/include/libomp" ])
    AC_CHECK_FILE(/usr/local/lib,             [ MAC_LDFLAGS="$MAC_LDFLAGS -L/usr/local/lib -Wl,-rpath,/usr/local/lib" ])
    AC_CHECK_FILE(/usr/local/lib/libomp,      [ MAC_LDFLAGS="$MAC_LDFLAGS -L/usr/local/lib/libomp -Wl,-rpath,/usr/local/lib/libomp" ])
  fi
  
  CPPFLAGS="$CPPFLAGS $MAC_CCPFLAGS"
  VICE_CPPFLAGS="$VICE_CPPFLAGS $MAC_CCPFLAGS"
  LDFLAGS="$LDFLAGS $MAC_LDFLAGS"
  VICE_LDFLAGS="$VICE_LDFLAGS $MAC_LDFLAGS"
  LIBS="$LIBS $MAC_FRAMEWORKS"
  ;;

dnl All other UN*X systems
*)
  is_unix=yes
  is_unix_x11=yes

  case "$host_os" in
  linux*)
    AC_DEFINE(LINUX_COMPILE,,[Are we compiling for Linux?])
    AM_CONDITIONAL(LINUX_COMPILE, true)
    ;;
  esac

  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"
  if test x"$enable_midi" = "xyes"; then
    AC_DEFINE(HAVE_MIDI,,[Enable support for MIDI.])
    HAVE_MIDI_SUPPORT="yes"
  fi
  if test x"$enable_rs232" != "xno"; then
    AC_DEFINE(HAVE_RS232DEV,,[Enable RS232 device emulation.])
    HAVE_RS232DEV_SUPPORT="yes"
  fi
  ;;
esac
fi

dnl check for debug build
if test x"$enable_debug" = "xyes"; then
  have_backtrace_symbols="no"
  DEBUGBUILD=1
  STRIP=":"
  DEBUG_SUPPORT="yes"
  AC_CHECK_HEADERS(execinfo.h,,)

  dnl PCBSD/FreeBSD/Haiku needs -lexecinfo for debug builds
  AC_CHECK_FUNC(backtrace_symbols,
                have_backtrace_symbols="yes",
                have_backtrace_symbols="no")

  if test x"$have_backtrace_symbols" != "xyes"; then
    AC_CHECK_LIB(execinfo,
                 backtrace_symbols,
                 [ LIBS="$LIBS -lexecinfo"
                   have_backtrace_symbols="yes" ],
                 AC_MSG_WARN("Could not find backtrace_symbols in either libc or libexecinfo. Either install libexecinfo, or disable debugging. Please note that --enable-debug is only available for Linux, *BSD, Solaris and OSX."))

  fi

  if test x"$have_backtrace_symbols" = "xyes"; then
    AC_DEFINE(HAVE_BT_SYMBOLS,,[Use backtrace facility of libC or libexecinfo])
    dnl Required for gcc to get proper backtraces
    VICE_LDFLAGS="$VICE_LDFLAGS -rdynamic"
  fi

else
  dnl Disable asserts
  VICE_CPPFLAGS="$VICE_CPPFLAGS -DNDEBUG"
  DEBUGBUILD=0
  dnl Remove super annoying horrible terminal window on Windows
  dnl (but not when using the headless 'UI')
  if test x"$is_win32" = "xyes" -a x"$enable_headlessui" != "xyes"; then
    VICE_CPPFLAGS="$VICE_CPPFLAGS -mwindows"
    VICE_CFLAGS="$VICE_CFLAGS -mwindows"
    VICE_CXXFLAGS="$VICE_CXXFLAGS -mwindows"
  fi
fi

AC_SUBST(DEBUGBUILD)

have_openmp="no"
if test x"$enable_openmp" != "xno"; then
  dnl
  dnl Check for native compiler support for OpenMP.
  dnl
  dnl It's probably there on Windows and Linux, probably not on macOS.
  dnl

  TEST_OPENMP_C=" int thread_count = 0;
                  #pragma omp parallel reduction(+:thread_count)
                  thread_count += 1;
                  if (thread_count > 1)
                    return 0;
                  return 1;"

  AC_MSG_CHECKING([for native OpenMP])
  ORIG_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS -fopenmp"
  AC_TRY_LINK([ #include <omp.h> ],
              [ $TEST_OPENMP_C ],
              [ AC_MSG_RESULT(yes)
                have_openmp="yes"
                VICE_CFLAGS="$VICE_CFLAGS -fopenmp"
                VICE_CXXFLAGS="$VICE_CXXFLAGS -fopenmp"
                VICE_LDFLAGS="$VICE_LDFLAGS -fopenmp" ],
              [ AC_MSG_RESULT(no) ])
  CFLAGS=$ORIG_CFLAGS

  if test x"$have_openmp" = "xno"; then
    if test x"$is_unix_macosx" = "xyes"; then
      dnl
      dnl Xcode ships clang without OpenMP, but it can be installed with macports / brew.
      dnl

      AC_MSG_CHECKING([for MacPorts / Homebrew OpenMP])
      ORIG_CFLAGS="$CFLAGS"
      CFLAGS="$CFLAGS -Xpreprocessor -fopenmp -lomp"
      AC_TRY_LINK([ #include <omp.h> ],
                  [ $TEST_OPENMP_C ],
                  [ AC_MSG_RESULT(yes)
                    have_openmp="yes"
                    VICE_CFLAGS="$VICE_CFLAGS -Xpreprocessor -fopenmp"
                    VICE_CXXFLAGS="$VICE_CXXFLAGS -Xpreprocessor -fopenmp"
                    LIBS="$LIBS -lomp"
                    ],
                  [ AC_MSG_RESULT(no)
                    CFLAGS=$ORIG_CFLAGS ])
      CFLAGS=$ORIG_CFLAGS

      if test x"$have_openmp" = "xno"; then
        echo "warning: OpenMP acceleration enabled, but not available (port/brew install libomp)"
      fi
    else
      echo "warning: OpenMP acceleration enabled, but not available"
    fi
  fi
fi


dnl Check for threading code debugging
AM_CONDITIONAL(HAVE_DEBUG_THREADS, test x"$enable_debug_threads" = "xyes")
if test x"$enable_debug_threads" = x"yes"; then
  DEBUG_THREADS_SUPPORT="yes"
  AC_DEFINE(HAVE_DEBUG_THREADS,,[Enable threading debug support])
fi


dnl Check and setup GTK3 compilation, only fail if the gtk3 ui was requested
if test x"$check_gtk3" = "xyes"; then

  PKG_CHECK_MODULES(GTK, [gtk+-3.0 >= 3.22], [have_gtk3_module=yes], [have_gtk3_module=no; AC_MSG_RESULT([no])])
  PKG_CHECK_MODULES(GLIB, [glib-2.0], [have_glib2_module=yes], [have_glib2_module=no; AC_MSG_RESULT([no])])

  dnl Extra tools required for Gtk builds
  dnl These programs live in libglib2.0-dev-bin on Debian

  dnl error out if gtk3 support is missing and gtk3 ui was requested
  if test x"$have_gtk3_module" = "xno" -o x"$have_glib2_module" = "xno"; then
    if test x"$enable_gtk3ui" = "xyes"; then
      AC_MSG_ERROR([GTK3 UI requested, but GTK3 support packages are missing])
    fi
  fi

  dnl Used to compile the vice.gresource.xml file
  AC_CHECK_PROG(GLIB_COMPILE_RESOURCES, [glib-compile-resources], [glib-compile-resources], [no])
  AS_IF([test x"$GLIB_COMPILE_RESOURCES" = "xno"],
        [AC_MSG_ERROR([glib-compile-resources is missing, please install glib development binaries])])
  dnl Used by VTE for signal marshalling
  AC_CHECK_PROG(GLIB_GENMARSHAL, [glib-genmarshal], [glib-genmarshal], [no])
  AS_IF([test x"$GLIB_GENMARSHAL" = "xno"],
        [AC_MSG_ERROR([glib-genmarshal is missing, please install glib development binaries])])

  dnl only continue to test if gtk3 support was present
  if test x"$have_gtk3_module" = "xyes" -a x"$have_glib2_module" = "xyes"; then

    VICE_CFLAGS="$VICE_CFLAGS $GLIB_CFLAGS $GTK_CFLAGS"
    VICE_CXXFLAGS="$VICE_CXXFLAGS $GLIB_CFLAGS $GTK_CFLAGS"
    LIBS="$LIBS $GTK_LIBS $GLIB_LIBS"

    if test x"$is_unix_macosx" = "xyes"; then
      dnl GTK3-FIXME: put OSX specific checks here
      :
    elif test x"$is_win32" = "xyes"; then
      dnl GTK3-FIXME: put windows specific checks here
      :
    else
      dnl GTK3-FIXME: put *nix specific checks here
      :
    fi

    dnl enforce OpenGL/GLEW usability unless explicitly disabled
    if test x"$is_unix_macosx" = "xyes"; then
      AC_MSG_CHECKING(whether we can use the OpenGL Framework)
      old_LIBS="$LIBS"
      LIBS="$LIBS -framework OpenGL"
      AC_TRY_LINK([#define GL_GLEXT_PROTOTYPES
                   #include <OpenGL/gl.h>],
                   [glUniform4f(0,1,2,3,4);],
                   [AC_MSG_RESULT(yes);
                    have_opengl_lib=yes],
                   [AC_MSG_RESULT(no);
                    LIBS="$old_LIBS"])
      if test x"$have_opengl_lib" != "xyes"; then
        AC_MSG_ERROR([Cannot find the OpenGL framework. Something is seriously wrong with your build environment.])
      fi
      AC_SEARCH_LIBS(glewInit, [GLEW glew32], [have_glew=yes], [have_glew=no])
      if test x"$have_glew" != "xyes"; then
        AC_MSG_ERROR([Cannot find the OpenGL Extension Wrangler Library, GLEW. (port/brew install glew)])
      fi
    else
      dnl Find where the GL functions live on this system
      old_clags="$CFLAGS"
      CFLAGS="$VICE_CFLAGS"
      PKG_CHECK_MODULES(GLEW, [glew], have_pkg_glew="yes")
      if test x"$have_pkg_glew" = "xyes"; then
          LIBS="$LIBS $GLEW_LIBS"
      fi
      AC_SEARCH_LIBS(glViewport, [GL opengl32], [have_opengl_lib=yes], [have_opengl_lib=no])
      AC_SEARCH_LIBS(glewInit, [GLEW glew32], [have_glew=yes], [have_glew=no])

      if test x"$have_opengl_lib" != "xyes" -o x"$have_glew" != "xyes"; then
        AC_MSG_CHECKING(whether the opengl32 and glew32 libraries work anyway)
        old_LIBS="$LIBS"
        LIBS="$LIBS -lopengl32 -lglew32"
        AC_TRY_LINK([#include <GL/glew.h>],
                    [glewInit();],
                    [AC_MSG_RESULT(yes);
                     have_opengl_lib=yes;
                     have_glew=yes],
                    [AC_MSG_RESULT(no);
                     LIBS="$old_LIBS"])
      fi

      CFLAGS="$old_CFLAGS"

      if test x"$have_opengl_lib" != "xyes" -o x"$have_glew" != "xyes"; then
        AC_MSG_ERROR([Could not find OpenGL and GLEW libraries, aborting.])
      fi
    fi

    AC_DEFINE(USE_GTK3UI,,[Use GTK3 UI.])
    if test x"$enable_debug_gtk3ui" = "xyes"; then
      AC_DEFINE(HAVE_DEBUG_GTK3UI,,[Add GTK3 UI debugging code.])
    fi

    dnl Platform canonical names for Win32-GTK3 have names like "i686-w64-mingw32"
    case "$host_os" in
      *mingw32)
          host_os=mingw32-gtk3
          is_win32_gtk3=yes

          dnl Needed for cross-building win32, -static makes some CoInitialize
          dnl check fail, so I had to leave that out. This also works on msys2.
          LIBS="$LIBS -static-libgcc"

    esac

    dnl Don't check for fontconfig on MacOS or Windows, we don't use fontconfig
    dnl directly on those platforms
    if test x"$is_unix_macosx" != "xyes" -a x"$is_win32" != "xyes"; then
      dnl check for fontconfig
      PKG_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.0.0],
          [HAVE_FONTCONFIG_SUPPORT=yes; LIBS="$LIBS -lfontconfig"],
          AC_MSG_ERROR([failed to find fontconfig]))
      AC_DEFINE(HAVE_FONTCONFIG,,[Use fontconfig for custom fonts.])
    fi

    dnl now that the GTK3 UI support has been detected, define enable_gtk3ui and undefine the others to prevent checks
    enable_gtk3ui=yes
    enable_sdl1ui=no
    enable_sdl2ui=no
    enable_headlessui=no
    found_gui=gtk3


    dnl Gtk3 always has HW scaling
    AC_DEFINE(HAVE_HWSCALE,,[Enable arbitrary window scaling])
    HAVE_HWSCALE_SUPPORT="yes"
  fi
fi

dnl Check if sdl2 ui should be checked
if test x"$check_guis" = "xyes"; then
  if test x"$enable_sdl2ui" != "xno"; then
    check_sdl2=yes
  fi
else
  if test x"$enable_sdl2ui" = "xyes"; then
    check_sdl2=yes
  fi
fi
if test x"$with_sdlsound" = "xyes" -a x"$enable_sdl1ui" != "xyes"; then
  check_sdl2=yes
  if test x"$enable_headlessui" = "xyes" -o x"$enable_gtk3ui" = "xyes"; then
    check_sdlaudio_only=yes
    enable_sdl1ui=no
    enable_sdl2ui=no
  fi
fi

dnl Check and setup SDL2 compilation, only fail if the sdl2 ui was requested
if test x"$check_sdl2" = "xyes"; then
  user_cflags="$CFLAGS"
  user_cxxflags="$CXXFLAGS"
  backup_CFLAGS="$VICE_CFLAGS"
  backup_CXXFLAGS="$VICE_CXXFLAGS"
  old_libs=$LIBS

  found_sdl2=no

  PKG_CHECK_MODULES(SDL2, sdl2, [
    use_sdl_prefix=no
    found_sdl2=yes
    VICE_CFLAGS="$VICE_CFLAGS $SDL2_CFLAGS"
    VICE_CXXFLAGS="$VICE_CXXFLAGS $SDL2_CFLAGS"
    LIBS="$LIBS $SDL2_LIBS"
  ],[
    dnl fail if SDL2 ui was requested, otherwise restore flags and continue
    if test x"$enable_sdl2ui" = "xyes"; then
      AC_MSG_ERROR([SDL 2.x UI requested, but SDL 2.x library is missing.])
    fi
  ])

  dnl only continue if sdl2 was found
  if test x"$found_sdl2" = "xyes"; then

    dnl check for the 2 cases where audio needs to be checked
    check_sdl2audio=no
    if test x"$enable_sdl2ui" = "xyes" -o x"$with_sdlsound" = "xyes"; then
      check_sdl2audio=yes
    fi

    user_CFLAGS="$CFLAGS"
    user_CXXFLAGS="$CXXFLAGS"
    CFLAGS="$VICE_CFLAGS"
    CXXFLAGS="$VICE_CXXFLAGS"

    dnl only do if audio needs to be checked
    if test x"$check_sdl2audio" = "xyes"; then
      AC_MSG_CHECKING(for SDL audio support)
      AC_TRY_LINK([#include <SDL_audio.h>],
                  [SDL_OpenAudio(NULL, NULL)],
                  [AC_MSG_RESULT(yes);
                    USE_SDL_AUDIO_SUPPORT="yes";
                    AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])],
                  [AC_MSG_RESULT(no);])

      dnl fail if --with-sdlsound was given
      if test x"$USE_SDL_AUDIO_SUPPORT" != "xyes"; then
        if test x"$with_sdlsound" = "xyes"; then
          AC_MSG_ERROR([SDL sound support missing])
        fi
      else
        SOUND_DRIVERS="$SOUND_DRIVERS soundsdl.o"
      fi
    fi

    dnl SDL2 now definitely works, so set the last few settings.
    dnl SDL2 is much more consistent than SDL1 so none of these
    dnl actually require tests.
    if test x"$enable_sdl2ui" != "xno"; then
      AC_DEFINE(USE_SDL2UI,,[Enable SDL 2.x UI support.])
      AC_DEFINE(HAVE_FULLSCREEN,,[Enable Fullscreen support.])
      HAVE_FULLSCREEN_SUPPORT="yes"
      AC_DEFINE(HAVE_HWSCALE,,[Enable arbitrary window scaling])
      HAVE_HWSCALE_SUPPORT="yes"

      AC_CHECK_FUNCS(SDL_NumJoysticks)

      dnl now that the SDL 2.0 UI support has been detected, define
      dnl enable_sdl2ui and undefine the others to prevent checks

      if test x"$check_sdlaudio_only" != "xyes"; then
        enable_gtk3ui=no
        enable_sdl1ui=no
        enable_sdl2ui=yes
        enable_headlessui=no
        found_gui=sdl2
      fi

      dnl Require SDL2_image
      PKG_CHECK_MODULES(SDL2_IMAGE,
                        [SDL2_image >= 2.0.0],
                        [have_sdl2_image=yes],
                        [have_sdl2_image=no; AC_MSG_RESULT([no])])
      if test x"$have_sdl2_image" = "xyes"; then
        VICE_CFLAGS="$VICE_CFLAGS $SDL2_IMAGE_CFLAGS"
        VICE_CXXFLAGS="$VICE_CXXFLAGS $SDL2_IMAGE_CFLAGS"
        LIBS="$LIBS $SDL2_IMAGE_LIBS"
      else
        AC_MSG_ERROR([SDL2_image-dev is required.])
      fi
    fi
    # LIBS="$LIBS -static-libstdc++"

    CFLAGS="$user_CFLAGS"
    CXXFLAGS="$user_CXXFLAGS"
  fi
fi

dnl Check if sdl ui should be checked
if test x"$check_guis" = "xyes"; then
  if test x"$enable_sdl1ui" != "xno"; then
    check_sdl1=yes
  fi
else
  if test x"$enable_sdl1ui" = "xyes"; then
    check_sdl1=yes
  fi
fi
if test x"$with_sdlsound" = "xyes"; then
  check_sdl1=yes
fi


dnl Check and setup SDL 1.2 compilation.
if test x"$check_sdl1" = "xyes"; then

  dnl check for the 2 cases where audio needs to be checked
  check_sdlaudio=no
  if test x"$ac_cv_lib_SDL2_SDL_OpenAudio" != "xyes"; then
    if test x"$enable_sdl1ui" = "xno"; then
      if test x"$with_sdlsound" = "xyes"; then
        check_sdlaudio=yes
      fi
    else
      check_sdlaudio=yes
    fi
  fi

  dnl fail if SDL ui was requested
  if test x"$sdl_config" = "xno" -a x"$enable_sdl1ui" = "xyes"; then
    AC_MSG_ERROR([SDL UI requested, but sdl-config is missing])
  fi

  dnl only continue if sdl-config was found
  if test x"$sdl_config" != "xno"; then
    user_cflags="$CFLAGS"
    user_cxxflags="$CXXFLAGS"
    old_libs=$LIBS

    CFLAGS="$VICE_CFLAGS `$sdl_config --cflags`"
    CXXFLAGS="$VICE_CXXFLAGS `$sdl_config --cflags`"
    LIBS="$LIBS `$sdl_config --libs`"

    dnl only do if audio needs to be checked
    if test x"$check_sdlaudio" = "xyes"; then
      AC_CHECK_HEADERS(SDL/SDL_audio.h,[AC_CHECK_LIB(SDL, SDL_OpenAudio,
                       [use_sdl_prefix=yes;
                        USE_SDL_AUDIO_SUPPORT="yes";
                        AC_DEFINE(USE_SDL_PREFIX,,[Enable SDL prefix for header inclusion.])
                        AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])],
                       [CFLAGS="$user_cflags"; CXXFLAGS="$user_cxxflags"; LIBS=$old_libs; break],$EXTRA_SDL_LIBS)],
                       [CFLAGS="$user_cflags"; CXXFLAGS="$old_cxxflags"; LIBS=$old_libs; break])

      if test x"$ac_cv_lib_SDL_SDL_OpenAudio" != "xyes"; then
        unset ac_cv_lib_SDL_SDL_OpenAudio
        AC_CHECK_HEADERS(SDL_audio.h,[AC_CHECK_LIB(SDL, SDL_OpenAudio,
                         [use_sdl_prefix=no;
                          USE_SDL_AUDIO_SUPPORT="yes";
                          AC_DEFINE(USE_SDL_AUDIO,,[Enable SDL sound support.])],
                         [CFLAGS="$user_cflags"; CXXFLAGS="$user_cxxflags"; LIBS=$old_libs; break],$EXTRA_SDL_LIBS)],
                         [CFLAGS="$old_cflags"; CXXFLAGS="$old_cxxflags"; LIBS=$old_libs; break])
      fi

      dnl fail if --with-sdlsound was given
      if test x"$ac_cv_lib_SDL_SDL_OpenAudio" != "xyes"; then
        if test x"$with_sdlsound" = "xyes"; then
          AC_MSG_ERROR([SDL sound support missing])
        fi
      else
        SOUND_DRIVERS="$SOUND_DRIVERS soundsdl.o"
      fi
    fi

    dnl only check if SDL 1.2 ui is needed
    if test x"$enable_sdl1ui" != "xno"; then
      AC_CHECK_HEADERS(SDL/SDL.h,[AC_CHECK_LIB(SDL, SDL_SetVideoMode,
                         [use_sdl_prefix=yes;
                          AC_DEFINE(USE_SDL_PREFIX,,[Enable SDL prefix for header inclusion.])
                          AC_DEFINE(USE_SDLUI,,[Enable SDL 1.2 UI support.])],
                         [CFLAGS="$user_cflags"; CXXFLAGS="$user_cxxflags"; LIBS=$old_libs; break],$EXTRA_SDL_LIBS)],
                         [CFLAGS="$user_cflags"; CXXFLAGS="$user_cxxflags"; LIBS=$old_libs; break])

        if test x"$ac_cv_lib_SDL_SDL_SetVideoMode" != "xyes"; then
          unset ac_cv_lib_SDL_SDL_SetVideoMode
          AC_CHECK_HEADERS(SDL.h,[AC_CHECK_LIB(SDL, SDL_SetVideoMode,
                           [use_sdl_prefix=no;
                            AC_DEFINE(USE_SDLUI,,[Enable SDL 1.2 UI support.])],
                           [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break],$EXTRA_SDL_LIBS)],
                           [CFLAGS=$old_cflags; CXXFLAGS=$old_cxxflags; LIBS=$old_libs; break])
        fi

        dnl fail if SDL 1.2 ui was requested
        if test x"$ac_cv_lib_SDL_SDL_SetVideoMode" != "xyes" -a x"$enable_sdl1ui" = "xyes"; then
          AC_MSG_ERROR([SDL 1.2 headers and/or libraries missing])
        fi

      dnl only continue if SDL headers/libs are present
      if test x"$ac_cv_lib_SDL_SDL_SetVideoMode" = "xyes"; then
        AC_DEFINE(HAVE_FULLSCREEN,,[Enable Fullscreen support.])
        HAVE_FULLSCREEN_SUPPORT="yes"

        AC_CHECK_FUNCS(SDL_NumJoysticks)

        if test x"$enable_hwscale" != "xno"; then
          if test x"$is_unix_macosx" = "xyes" -o x"$is_win32" = "xyes"; then
            AC_MSG_CHECKING(whether we can use the OpenGL Framework)
            old_LIBS="$LIBS"
            if test x"$is_unix_macosx" = "xyes"; then
              LIBS="$LIBS -framework OpenGL"
            else
              LIBS="$LIBS -lopengl32"
            fi
            if test x"$use_sdl_prefix" = "xyes"; then
              AC_TRY_LINK([#include <SDL/SDL_opengl.h>],
                          [glViewport(1,2,3,4)],
                          [AC_MSG_RESULT(yes);
                           have_opengl_lib=yes],
                          [AC_MSG_RESULT(no);
                           LIBS="$old_LIBS"])
            else
              AC_TRY_LINK([#include <SDL_opengl.h>],
                          [glViewport(1,2,3,4)],
                          [AC_MSG_RESULT(yes);
                           have_opengl_lib=yes],
                          [AC_MSG_RESULT(no);
                           LIBS="$old_LIBS"])
            fi
          else
            AC_SEARCH_LIBS(glViewport, [GL], [have_opengl_lib=yes], [have_opengl_lib=no])
          fi

          if test x"$have_opengl_lib" != "xyes"; then
            AC_MSG_ERROR(The SDL 1.2 UI requires OpenGL for hardware scaling. Install OpenGL development headers or set --disable-hwscale to disable scaling.)
          fi
        fi

        if test x"$enable_hwscale" != "xno"; then
          AC_DEFINE(HAVE_HWSCALE,,[Enable arbitrary window scaling])
          HAVE_HWSCALE_SUPPORT="yes"
        fi

        dnl check for the SDL_main.h header
        if test x"$use_sdl_prefix" = "xyes"; then
          AC_CHECK_HEADERS(SDL/SDL_main.h)
        else
          AC_CHECK_HEADERS(SDL_main.h)
        fi

        AC_MSG_CHECKING(whether we can use the SDLmain library)
        old_LIBS="$LIBS"
        LIBS="$LIBS -lSDLmain -lSDL $EXTRA_SDL_LIBS"
        if test x"$use_sdl_prefix" = "xyes"; then
          AC_TRY_LINK([#include <SDL/SDL_main.h>
                       int main(int argc, char *argv[])
                       { return 0; }
                       #undef main
                       #define main something_else],
                      [return 0;],
                      [AC_MSG_RESULT(yes);
                       have_sdlmain=yes],
                      [AC_MSG_RESULT(no);
                       LIBS="$old_LIBS"])
        else
          AC_TRY_LINK([#include <SDL_main.h>
                       int main(int argc, char *argv[])
                       { return 0; }
                       #undef main
                       #define main something_else],
                      [return 0;],
                      [AC_MSG_RESULT(yes);
                       have_sdlmain=yes],
                      [AC_MSG_RESULT(no);
                       LIBS="$old_LIBS"])
        fi

        if test x"$have_sdlmain" != "xyes"; then
          AC_MSG_CHECKING(whether we can use the SDLmain library when adding -lmingw32)
          old_LIBS="$LIBS"
          LIBS="$LIBS -lmingw32 -lSDLmain -lSDL"
          if test x"$use_sdl_prefix" = "xyes"; then
            AC_TRY_LINK([#include <SDL/SDL_main.h>
                         int main(int argc, char *argv[])
                         { return 0; }
                         #undef main
                         #define main something_else],
                        [return 0;],
                        [AC_MSG_RESULT(yes);
                         have_sdlmain=yes],
                        [AC_MSG_RESULT(no);
                         LIBS="$old_LIBS"])
          else
            AC_TRY_LINK([#include <SDL_main.h>
                         int main(int argc, char *argv[])
                         { return 0; }
                         #undef main
                         #define main something_else],
                        [return 0;],
                        [AC_MSG_RESULT(yes);
                         have_sdlmain=yes],
                        [AC_MSG_RESULT(no);
                         LIBS="$old_LIBS"])
          fi
        fi

        if test x"$have_sdlmain" = "xyes"; then
          AC_DEFINE(HAVE_SDLMAIN,,[Enable SDLmain replacement])
        fi

        dnl Require SDL_image
        dnl The version number I sucked out of my thumb, on my Debian the
        dnl version is 1.2.12
        dnl
        PKG_CHECK_MODULES(SDL_IMAGE,
                          [SDL_image >= 1.2.0],
                          [have_sdl_image=yes],
                          [have_sdl_image=no; AC_MSG_RESULT([no])])
        if test x"$have_sdl_image" = "xyes"; then
          LIBS="$LIBS -lSDL_image"
        else
          AC_MSG_ERROR([SDL_image1.2-dev is required.])
        fi

        dnl now that the SDL1 UI support has been detected, define enable_sdl1ui and undefine the others to prevent checks
        if test x"$check_sdlaudio_only" != "xyes"; then
          enable_gtk3ui=no
          enable_sdl1ui=yes
          enable_sdl2ui=no
          enable_headlessui=no
          found_gui=sdl1
        fi
      fi
    fi
  fi
fi

if test x"$enable_headlessui" = "xyes"; then
  AC_DEFINE(USE_HEADLESSUI,,[Enable Headless UI support.])
  enable_gtk3ui=no
  enable_sdl1ui=no
  enable_sdl2ui=no
  found_gui=headless
fi

dnl check if any gui support was found
if test x"$found_gui" = "x"; then
  AC_MSG_ERROR([No GUI support found])
fi


dnl Check if --enable-debug-gtk3ui was requested but the UI isn't gtk3
if test x"$enable_debug_gtk3ui" = "xyes" -a x"$enable_gtk3ui" != "xyes"; then
    AC_MSG_ERROR([Requested Gtk3 UI debugging, but the requested UI isn't Gtk3.])
fi


dnl Check if --disable-hwscale was requested for the Gtk3 UI
if test x"$enable_gtk3ui" = "xyes" -a x"$enable_hwscale" = "xno"; then
  AC_MSG_ERROR([The option `--disable-hwscale` is illegal for the Gtk3 UI. Please remove the option and make sure the OpenGL development headers are installed.])
fi


dnl Check if --disable-hwscale was requested for the Gtk3 UI
if test x"$enable_sdl2ui" = "xyes" -a x"$enable_hwscale" = "xno"; then
  AC_MSG_ERROR([The option `--disable-hwscale` is illegal for the SDL2 UI.])
fi



dnl check if sdl sound was requested but not found
if test x"$with_sdlsound" = "xyes"; then
  if test x"$USE_SDL_AUDIO_SUPPORT" != "xyes"; then
    AC_MSG_ERROR([No SDL sound support found])
  fi
fi

dnl are we putting emu into a background thread (requires UI code support)
if test x"$enable_gtk3ui" = "xyes"; then
  AC_DEFINE(USE_VICE_THREAD,,[UI and emu each on different threads])
  VICE_CFLAGS="$VICE_CFLAGS -pthread"
  VICE_CXXFLAGS="$VICE_CXXFLAGS -pthread"
  VICE_LDFLAGS="$VICE_LDFLAGS -pthread"
  show_multithreaded="yes"

  if test x"$is_unix_x11" = x"yes" -a x"$is_unix_macosx" != x"yes"; then
    dnl xlib is used for adding a native child window for opengl rendering
    LIBS="$LIBS -lX11"
  fi

else
  show_multithreaded="no"
fi

if test x"$is_win32" = "xyes" -a x"$enable_sdl1ui" != "xyes" -a x"$enable_sdl2ui" != "xyes" -a x"$enable_headlessui" != "xyes"; then
  dinput_header_no_lib="no"

  AC_CHECK_HEADER(dinput.h,
              [ HAVE_DINPUT_SUPPORT="yes";
                JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS joystick_win32_directinput.o";
                AC_DEFINE(HAVE_DINPUT,,[Use DirectInput joystick driver]) ]
              [ AC_MSG_CHECKING(for -ldinput8) ]
              [SAVELIBS="$LIBS"] [ LIBS="-ldinput8 $LIBS" ]
              [ AC_LINK_IFELSE([
                               AC_LANG_PROGRAM([
                               #define DIRECTINPUT_VERSION 0x800
                               #include <dinput.h>
                               ],[return DirectInput8Create(0,0,0,0,0);])
                               ],
                            [ AC_DEFINE(HAVE_DINPUT_LIB, [], [dinput8.lib or libdinput8.a are present]) ]
                            [ AC_MSG_RESULT(yes) ],
                            [ dinput_header_no_lib="yes" ]
                            [ LIBS="$SAVELIBS" ]
                            [ AC_MSG_RESULT(no) ]
              )]
     )
fi


dnl Check/setup XDG desktop files support
dnl
dnl XDG .desktop files are only supported for the Gtk3 UI on Unix (excl. MacOS)
dnl
AM_CONDITIONAL(INSTALL_DESKTOP_FILES, false)
if test x"$enable_desktop_files" = "xyes"; then
    dnl Check Gtk3 UI
    if test x"$enable_gtk3ui" != "xyes"; then
        AC_MSG_ERROR([XDG desktop files requested but UI is not Gtk3.])
    fi
    dnl Check OS (Unix)
    if test x"$is_unix_x11" != "xyes"; then
        AC_MSG_ERROR([XDG desktop files requested but OS is not Unix.])
    fi
    dnl Check OS (not MacOS)
    if test x"$is_unix_macos" = "xyes"; then
        AC_MSG_ERROR([XDG desktop files requested but OS is MacOS.])
    fi
    dnl Check for xdg-desktop-menu
    AC_CHECK_PROG(XDG_DESKTOP_MENU, xdg-desktop-menu, xdg-desktop-menu, no)
    echo "$XDG_DESKTOP_MENU"
    if test x"$XDG_DESKTOP_MENU" = "xno"; then
        AC_MSG_ERROR([XDG desktop files requested but required tool xdg-desktop-menu is missing. Please install xgd-utils.])
    fi

    dnl We got the UI + OS + tools:
    USE_DESKTOP_FILES="yes"
    AM_CONDITIONAL(INSTALL_DESKTOP_FILES, true)
    AC_SUBST([XDG_DESKTOP_MENU], ["$XDG_DESKTOP_MENU"])

fi


dnl Check for the icotool binary to generate Windows .ico files
AC_CHECK_PROG(ICOTOOL, icotool, icotool, no)
if test x"$is_win32" = "xyes"; then
  if test x"$ICOTOOL" = "xno"; then
    AC_MSG_ERROR([Building for Windows, but icotool is missing. Please install icoutils."])
  fi
fi


dnl Extension for executable files in this system
AC_EXEEXT

AC_CHECK_LIB(iconv, libiconv_open,,)

dnl Check if --param inline-unit-growth=60 can be used.
old_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -Werror --param inline-unit-growth=60"
AC_MSG_CHECKING([if the compiler accepts --param inline-unit-growth=60])
AC_TRY_COMPILE([],
               [int test;],
               [ AC_MSG_RESULT(yes)
                 INLINE_UNIT_GROWTH="--param inline-unit-growth=60"
                ],
               [ AC_MSG_RESULT(no)
                INLINE_UNIT_GROWTH=""
                ])
CFLAGS=$old_CFLAGS
AC_SUBST(INLINE_UNIT_GROWTH)

dnl Check if --param max-inline-insns-single=600 can be used.
old_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -Werror --param max-inline-insns-single=600"
AC_MSG_CHECKING([if the compiler accepts --param max-inline-insns-single=600])
AC_TRY_COMPILE([],
               [int test;],
               [ AC_MSG_RESULT(yes)
                 MAX_INLINE_INSN_SINGLE="--param max-inline-insns-single=600"
                ],
               [ AC_MSG_RESULT(no)
                MAX_INLINE_INSN_SINGLE=""
                ])
CFLAGS=$old_CFLAGS
AC_SUBST(MAX_INLINE_INSN_SINGLE)


dnl Check for SID engines
dnl
dnl FastSID is disabled by default, so we check against "yes", ReSID is enabled
dnl by default so we check against "no" ($with_resid being empty means the
dnl default, ie "yes")
dnl
dnl Remove this check to allow building without a SID engine
if test x"$with_fastsid" != "xyes" -a x"$with_resid" = "xno"; then
  AC_MSG_ERROR([Neither FastSID nor ReSID sound engine enabled, please enable at least one.])
fi


dnl FastSID
AM_CONDITIONAL(HAVE_FASTSID, test x"$with_fastsid" = "xyes")
if test x"$with_fastsid" = "xyes"; then
  HAVE_FASTSID_SUPPORT="yes"
  AC_DEFINE(HAVE_FASTSID,,[This version provides FastSID support.])
fi

dnl Set output drivers to none
GFXOUTPUT_DRIVERS=""

RESID_DIR=
RESID_LIBS=
RESID_INCLUDES=
RESID_DEP=

RESID_DTV_DIR=
RESID_DTV_LIBS=
RESID_DTV_INCLUDES=
RESID_DTV_DEP=

dnl Set linker to C++ compiler/linker: even SDL builds use C++ code (linenoise-ng)
LINKCC='$(CXX)'

dnl disable reSID for certain platforms

RESIDSUB=""
RESIDDTVSUB=""

if test x"$with_resid" = "xno"; then
  dnl Do not attempt to configure reSID.
  dnl NOTE: no_recursion is set because directories specified with
  dnl AC_CONFIG_SUBDIRS are always recursed into regardless of where the
  dnl macro is used.
  dnl Another workaround must be found if other self-contained packages go
  dnl into VICE.
  
  dnl A workaround for an autoconf bug when not using/checking the C++
  dnl compiler, we'll define am__fastdepCXX_TRUE as #
  am__fastdepCXX_TRUE=#
  am__fastdepCXX_FALSE=
else
  AC_LANG_SAVE
  AC_LANG_CPLUSPLUS
  AC_PROG_CXX([g++ clang++ cc])

  dnl disable resid when no C++ compiler is found
  if test x"$CXX" != "x" ; then
    LINKCC='$(CXX)'

    dnl Set CXXFLAGS. Use -fno-exceptions for G++ if supported.
    if test "$ac_test_CXXFLAGS" != set; then
      if test "$GXX" = yes; then
        old_CXXFLAGS=$CXXFLAGS
        CXXFLAGS="$CXXFLAGS -fno-exceptions"
        AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works])
        AC_TRY_COMPILE([],
                       [ int test; ],
                       [ AC_MSG_RESULT(yes) ],
                       [ AC_MSG_RESULT(no)
                         CXXFLAGS=$old_CXXFLAGS
                         ])
      fi
    fi
    AC_PROG_CXXCPP
  fi

  if test x"$with_resid" = "xyes" -o x"$with_resid" = "x"; then
    AC_DEFINE(HAVE_RESID,,[This version provides ReSID support.])
    HAVE_RESID_SUPPORT="yes"
    AX_SUBDIRS_CONFIGURE([src/resid], [--disable-option-checking])
    RESID_DIR=resid
    RESID_LIBS="\$(top_builddir)/src/resid/libresid.a"
    RESID_INCLUDES="-I\$(top_builddir)/src/resid"
    RESID_DEP=libresid
    RESIDSUB=resid

    AC_DEFINE(HAVE_RESID_DTV,,[This version provides ReSID-DTV support.])
    AX_SUBDIRS_CONFIGURE([src/resid-dtv], [--disable-option-checking])
    RESID_DTV_DIR=resid-dtv
    RESID_DTV_LIBS="\$(top_builddir)/src/resid-dtv/libresiddtv.a"
    RESID_DTV_INCLUDES="-I\$(top_builddir)/src/resid-dtv"
    RESID_DTV_DEP=libresiddtv
    RESIDDTVSUB=resid-dtv
  fi
  AC_LANG_RESTORE
fi

AC_SUBST(RESIDSUB)
AC_SUBST(RESIDDTVSUB)

if test x"$RESIDSUB" = "xresid"; then
  AM_CONDITIONAL(RESID_DIR_USED, true)
else
  AM_CONDITIONAL(RESID_DIR_USED, false)
fi

AC_SUBST(LINKCC)

AM_CONDITIONAL(HAVE_RESID, test x"$with_resid" != "xno")

AC_SUBST(RESID_DIR)
AC_SUBST(RESID_LIBS)
AC_SUBST(RESID_INCLUDES)
AC_SUBST(RESID_DEP)

AM_CONDITIONAL(HAVE_RESID_DTV, test x"$with_resid" != "xno")
AC_SUBST(RESID_DTV_DIR)
AC_SUBST(RESID_DTV_LIBS)
AC_SUBST(RESID_DTV_INCLUDES)
AC_SUBST(RESID_DTV_DEP)

dnl Check for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADERS(sys/types.h)

AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T



dnl Define the type sizes. (No, it doesn't)
if [[ x"$ac_cv_prog_cc_cross" != "xyes" ]]; then
  dnl This appears to define `WORDS_BIGENDIAN`. Not sure if it gets AC_SUBST'ed
  AC_C_BIGENDIAN
else
  dnl if cross-compiling, we have to do this by hand
  dnl
  dnl This is bollocks, cross-compiling doesn't suddenly make the assumption
  dnl it's compiling for what looks like a 32-bit target. Any code that requires
  dnl a certain width of a type uses types from <stdint.h>, or at least it should,
  dnl this is VICE after all. --cpx
  echo "warning: assuming sizeof(unsigned short) == 2,"
  echo "                  sizeof(unsigned int) == 4,"
  echo "                  sizeof(unsigned long) == 4"
fi

if test x"$cross_compiling" = "xyes"; then
  AM_CONDITIONAL(CROSS, true)
  CROSS=true
else
  AM_CONDITIONAL(CROSS, false)
  CROSS=false
fi
AC_SUBST(CROSS)

AC_CHECK_SIZEOF(unsigned short, 2)
AC_CHECK_SIZEOF(unsigned int, 4)
AC_CHECK_SIZEOF(unsigned long, 4)


dnl Check for header files.
AC_HEADER_DIRENT
AC_CHECK_HEADERS(direct.h errno.h fcntl.h limits.h regex.h unistd.h strings.h \
sys/dirent.h sys/stat.h inttypes.h libgen.h sys/ioctl.h \
dir.h io.h process.h signal.h alloca.h wchar.h stdint.h sys/time.h)


AC_CHECK_HEADER(regexp.h,,,
                [#define    INIT        register char *sp = instring;
                 #define    GETC()      (*sp++)
                 #define    PEEKC()     (*sp)
                 #define    UNGETC(c)   sp
                 #define    RETURN(ptr) return NULL;
                 #define    ERROR(val)  _RegExpError(val)
])
AC_DECL_SYS_SIGLIST


dnl Check for capabilities support.
dnl
dnl Currently only makes sense on Linux/BSD for rawnet support.
AC_CHECK_HEADER(sys/capability.h,
  AC_CHECK_LIB(cap,cap_init,
                [ LIBS="$LIBS -lcap";
                  AC_DEFINE(HAVE_CAPABILITIES,,
                            [Support for POSIX capabilities.])
                  HAVE_CAPABILITIES_SUPPORT="yes"
                ]
  )
)


dnl ----- Dynamic Lib Loading Support -----
dynlib_support=no
DYNLIB_LIBS=
dnl check for dlopen support on unix and beos/haiku systems
if test x"$is_unix" = "xyes" -o x"$is_beos" = "xyes"; then
  AC_CHECK_HEADER(dlfcn.h,,)
  if test x"$ac_cv_header_dlfcn_h" = "xyes" ; then
    AC_CHECK_FUNC(dlopen,
                 [ DYNLIB_LIBS="";
                   AC_DEFINE(HAVE_DYNLIB_SUPPORT,,
                             [Support for dynamic library loading.])
                   dynlib_support=yes;
                   HAVE_DYNLIB_SUPPORT_TOO="yes"
                 ])
    if test x"$dynlib_support" != "xyes" ; then
      AC_CHECK_LIB(dl, dlopen,
                 [ DYNLIB_LIBS="-ldl";
                   AC_DEFINE(HAVE_DYNLIB_SUPPORT,,
                             [Support for dynamic library loading.])
                   dynlib_support=yes;
                   HAVE_DYNLIB_SUPPORT_TOO="yes";
                   LIBS="-ldl $LIBS"
                 ],,)
    fi
  fi
elif test x"$is_win32" = "xyes" ; then
  AC_DEFINE(HAVE_DYNLIB_SUPPORT,,[Support for dynamic library loading.])
  HAVE_DYNLIB_SUPPORT_TOO="yes"
fi
AC_SUBST(DYNLIB_LIBS)

dnl ----- Joystick support -----
JOY_LIBS=
if test x"$is_unix_x11" = "xyes" -a x"$enable_sdl1ui" != "xyes" -a x"$enable_sdl2ui" != "xyes" -a x"$enable_headlessui" != "xyes"; then
  AC_CHECK_HEADER(linux/joystick.h,
                  [
                   AC_CHECK_DECL(JS_VERSION,[
                       LINUX_JOYSTICK_SUPPORT="yes";
                        AC_DEFINE(LINUX_JOYSTICK,,
                              [Enable support for Linux style joysticks.])
                        JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS joystick_linux.o";
                   ],[],[#include <linux/joystick.h>])],)

  AC_CHECK_HEADER(machine/joystick.h,
                  [ BSD_JOYSTICK_SUPPORT="yes";
                    AC_DEFINE(HAVE_MACHINE_JOYSTICK_H,,
                              [Define to 1 if you have the <machine/joystick.h> header file.])
                    AC_DEFINE(BSD_JOYSTICK,,
                              [Enable support for BSD style joysticks.])],)

  if test x"$ac_cv_header_machine_joystick_h" != "xyes"; then
    AC_CHECK_HEADER(sys/joystick.h,
                    [ BSD_JOYSTICK_SUPPORT="yes";
                      AC_DEFINE(HAVE_SYS_JOYSTICK_H,,
                                [Define to 1 if you have the <sys/joystick.h> header file.])
                      AC_DEFINE(BSD_JOYSTICK,,
                                [Enable support for BSD style joysticks.])],)
  fi

  dnl NetBSD/FreeBSD USB joystick support
  usbhid_header=no
  usbhid_lib=no
  usb_lib=no
  AC_CHECK_LIB(usbhid, hid_get_report_desc, usbhid_lib=yes)
  if test x"$usbhid_lib" = "xyes" ; then
    AC_CHECK_HEADER(usbhid.h,
                    [AC_DEFINE(HAVE_USBHID_H,1,
                      [Define to 1 if you have the <usbhid.h> header file.])
                    usb_header=yes])
    AC_CHECK_HEADER(libusbhid.h,
                    [AC_DEFINE(HAVE_LIBUSBHID_H,1,
                      [Define to 1 if you have the <libusbhid.h> header file.])
                    usb_header=yes])

    if test x"$usb_header" = "xyes" ; then
      AC_DEFINE(HAS_USB_JOYSTICK,,[Enable emulation for USB joysticks.])
      JOY_LIBS="-lusbhid"
      HAS_USB_JOYSTICK_SUPPORT="yes"
    fi
  else
    AC_CHECK_LIB(usb, hid_get_report_desc, usb_lib=yes)
    if test x"$usb_lib" = "xyes"; then
      AC_CHECK_HEADER(usb.h,
                      [AC_DEFINE(HAVE_USB_H,1,
                        [Define to 1 if you have the <usb.h> header file.])
                      usb_header=yes])
      AC_CHECK_HEADER(libusb.h,
                      [AC_DEFINE(HAVE_LIBUSB_H,1,
                        [Define to 1 if you have the <libusb.h> header file.])
                      usb_header=yes])
      if test x"$usb_header" = "xyes" ; then
        AC_DEFINE(HAS_USB_JOYSTICK,,[Enable emulation for USB joysticks.])
        JOY_LIBS="-lusb"
        HAS_USB_JOYSTICK_SUPPORT="yes"
      fi
    fi
  fi
  if test x"$HAS_USB_JOYSTICK_SUPPORT" = "xyes"; then
    JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS joystick_bsd.o";
  fi
fi

if test x"$is_unix_macosx" = "xyes" -a x"$enable_sdl1ui" != "xyes" -a x"$enable_sdl2ui" != "xyes" -a x"$enable_headlessui" != "xyes"; then
  dnl --- Mac joystick support ---

  dnl check for HID Manager
  if test x"$enable_hidmgr" != "xno" ; then
    AC_CHECK_HEADER(IOKit/hid/IOHIDManager.h,,)
    if test x"$ac_cv_header_IOKit_hid_IOHIDManager_h" = "xyes" ; then
      AC_MSG_CHECKING(whether we can link the (mac) IOHIDManager)
      old_LIBS="${LIBS}"
      LIBS="$LIBS -framework IOKit -framework CoreServices"
      AC_TRY_LINK([#include <IOKit/hid/IOHIDManager.h>],
                  [IOHIDManagerCreate(NULL,0)],
                  [AC_MSG_RESULT(yes);
                   JOY_LIBS="-framework IOKit -framework CoreServices";
                   MAC_JOYSTICK_SUPPORT="yes";
                   HAS_HIDMGR_SUPPORT="yes";
                   AC_DEFINE(MAC_JOYSTICK,,[Enable Mac Joystick support.])
                   JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS joystick_osx.o";
                   ],
                  [AC_MSG_RESULT(no);
                   LIBS=${old_LIBS}])
      LIBS="${old_LIBS}"
    fi
  fi
fi
AC_SUBST(JOY_LIBS)

dnl Check for math library
AC_CHECK_HEADERS(math.h)
AC_CHECK_LIB(m, sqrt,,,$LIBS)


dnl ----- ZLib -----
ZLIB_LIBS=

if test x"$with_zlib" != "xno" ; then
  AC_CHECK_HEADER(zlib.h,,)
  if test x"$ac_cv_header_zlib_h" = "xyes" ; then
    ac_cv_lib_z_zlibVersion=yes
    AC_CHECK_LIB(z, zlibVersion,
               [ ZLIB_LIBS="-lz";
                 HAVE_ZLIB_SUPPORT="yes";
                 AC_DEFINE(HAVE_ZLIB,,
                 [Can we use the ZLIB compression library?]) ],,)
  fi
fi

AC_SUBST(ZLIB_LIBS)


dnl --- Curl ---
if test x"$with_libcurl" = "xyes"; then
  PKG_CHECK_MODULES(libcurl, [libcurl], [have_libcurl=yes], [have_libcurl=no])
  if test x"$have_libcurl" = "xno"; then
    AC_MSG_ERROR([libcurl support requested, but libcurl was not found.])
  fi
  HAVE_LIBCURL_SUPPORT="yes"
  VICE_CFLAGS="$VICE_CFLAGS $libcurl_CFLAGS"
  VICE_LDFLAGS="$VICE_LDFLAGS $libcurl_LDFLAGS"
  LIBS="$LIBS $libcurl_LIBS"
  AC_DEFINE(HAVE_LIBCURL, , [libcurl support])
fi


dnl ----- Netplay Support -----
NETPLAY_LIBS=
old_LIBS="$LIBS"
if test x"$is_unix_x11" = "xyes" -o x"$is_unix_macosx" = "xyes"; then

  dnl Check for needed network headers
  UNIX_NETWORK_HEADERS_PRESENT=yes
  AC_CHECK_HEADERS(sys/types.h unistd.h sys/socket.h sys/time.h sys/select.h netinet/in.h arpa/inet.h netdb.h,,
                   [UNIX_NETWORK_HEADERS_PRESENT=no],)

  if test x"$UNIX_NETWORK_HEADERS_PRESENT" = "xyes"; then

    dnl Check for possible extra needed network libraries
    AC_CHECK_LIB(intl, dgettext,[ NETPLAY_LIBS="-lintl $NETPLAY_LIBS";
                                  LIBS="-lintl $LIBS"],,)
    AC_CHECK_LIB(nsl, gethostbyname,[ NETPLAY_LIBS="-lnsl $NETPLAY_LIBS";
                                      LIBS="-lnsl $LIBS"],,)
    AC_CHECK_LIB(socket, gethostbyname,[ NETPLAY_LIBS="-lsocket $NETPLAY_LIBS";
                                         LIBS="-lsocket $LIBS"],,)
    AC_CHECK_LIB(bsd, gethostbyname,[ NETPLAY_LIBS="-lbsd $NETPLAY_LIBS";
                                      LIBS="-lbsd $LIBS"],,)
    AC_CHECK_LIB(net, gethostbyname,[ NETPLAY_LIBS="-lnet $NETPLAY_LIBS";
                                      LIBS="-lnet $LIBS"],,)
    AC_CHECK_LIB(inet, gethostbyname,[ NETPLAY_LIBS="-linet $NETPLAY_LIBS";
                                       LIBS="-linet $LIBS"],,)

    dnl Check for needed functions
    UNIX_NETWORK_FUNCS_PRESENT=yes

    dnl Check for netinet/tcp.h
    AC_CHECK_HEADERS([netinet/tcp.h])

    AC_CHECK_FUNCS(socket send bind listen gethostbyname connect recv accept,,
                   [UNIX_NETWORK_FUNCS_PRESENT=no],)

    if test x"$UNIX_NETWORK_FUNCS_PRESENT" = "xyes"; then
      AC_DEFINE(HAVE_NETWORK,,[Enable netplay support])
      HAVE_NETWORK_SUPPORT="yes"
      AC_DEFINE(HAVE_RS232NET,,[Enable RS232 network support])
      HAVE_RS232NET_SUPPORT="yes"
      AC_CHECK_FUNCS(htons htonl)
      AC_CHECK_FUNCS(getdtablesize getrlimit)
      AC_MSG_CHECKING([For socklen_t])
      AC_TRY_COMPILE([#include <sys/types.h>
                      #include <sys/socket.h>],
                     [socklen_t foo; foo = 1235;],
                     [AC_DEFINE(HAVE_SOCKLEN_T,,[Define if the socklen_t type is present.])
                      AC_MSG_RESULT(yes)],
                     [AC_MSG_RESULT(no)])

      AC_MSG_CHECKING([for in_addr_t])
      AC_TRY_COMPILE([#include <sys/types.h>
                      #include <stdlib.h>
                      #include <stddef.h>
                      #include <netinet/in.h>], [in_addr_t foo;],
                      [AC_DEFINE(HAVE_IN_ADDR_T,,[Define if the in_addr_t type is present.])
                       AC_MSG_RESULT(yes)],
                      [AC_MSG_RESULT(no)])

      AC_MSG_CHECKING([for Unix domain sockets])
      AC_TRY_COMPILE([#include <sys/socket.h>
                      #include <sys/un.h>], [
                      static struct sockaddr_un addr;
                      socket(AF_UNIX, SOCK_STREAM, 0);],
                      [AC_DEFINE(HAVE_UNIX_DOMAIN_SOCKETS,,[Define if Unix domain sockets are supported])
                      AC_MSG_RESULT(yes)],
                      AC_MSG_RESULT(no))

    fi
  fi
elif test x"$is_beos" = "xyes"; then

  dnl Check for needed network headers
  BEOS_NETWORK_HEADERS_PRESENT=yes
  AC_CHECK_HEADERS(sys/socket.h netdb.h ByteOrder.h,,
                   [BEOS_NETWORK_HEADERS_PRESENT=no],)

  if test x"$BEOS_NETWORK_HEADERS_PRESENT" = "xyes"; then

    dnl Check for possible extra needed network libraries

    AC_CHECK_LIB(network, gethostbyname,[ NETPLAY_LIBS="-lnetwork $NETPLAY_LIBS";
                                      LIBS="-lnetwork $LIBS"],,)

    AC_CHECK_LIB(net, gethostbyname,[ NETPLAY_LIBS="-lnet -lnetapi $NETPLAY_LIBS";
                                      LIBS="-lnet -lnetapi $LIBS"],,)

    dnl Check for needed functions

    BEOS_NETWORK_FUNCS_PRESENT=yes

    AC_CHECK_FUNCS(socket send bind listen gethostbyname connect recv accept,,
                   [BEOS_NETWORK_FUNCS_PRESENT=no],)

    if test x"$BEOS_NETWORK_FUNCS_PRESENT" = "xyes"; then
      AC_DEFINE(HAVE_NETWORK,,[Enable netplay support])
      HAVE_NETWORK_SUPPORT="yes"
      AC_DEFINE(HAVE_RS232NET,,[Enable RS232 network support])
      HAVE_RS232NET_SUPPORT="yes"
      AC_CHECK_FUNCS(getdtablesize getrlimit)
    fi
  fi
fi

dnl Check for availability of IPV6
if test x"$is_unix_x11" = "xyes" -o x"$is_unix_macosx" = "xyes" ; then
  if test x"$UNIX_NETWORK_FUNCS_PRESENT" = "xyes"; then
    AC_MSG_CHECKING([if IPV6 should be enabled])
    if test x"$enable_ipv6" != "xno"; then
      have_ipv6=no
      AC_TRY_COMPILE([
        #include <sys/socket.h>
        #include <sys/types.h>
        #include <netinet/in.h>], [
        struct sockaddr_storage ss;
        struct in6_addr in6;
        socket(AF_INET6, SOCK_STREAM, 0);
        in6 = in6addr_any;
        ],
        have_ipv6=yes,
        have_ipv6=no
      )
      AC_MSG_RESULT($have_ipv6)

      if test $have_ipv6 = yes; then
        have_broken_ss_family=no

        dnl on some platforms, the structure sockaddr doesn't have a
        dnl ss_family, but __ss_family. If we find no ss_family then we
        dnl check for __ss_family, and if found define NEED_PREFIXED_SS_FAMILY.
        AC_MSG_CHECKING([struct sockaddr::ss_family])
        AC_TRY_COMPILE([
          #include <sys/socket.h>
          #include <sys/types.h>], [
          struct sockaddr_storage ss ;
          ss.ss_family = 0 ;
          ],
          have_ss_family=yes,
          have_ss_family=no
        )
        AC_MSG_RESULT($have_ss_family)
        if test x"$have_ss_family" = "xno" ; then
          AC_MSG_CHECKING([broken struct sockaddr::ss_family])
          AC_TRY_COMPILE([
            #include <sys/socket.h>
            #include <sys/types.h>], [
            struct sockaddr_storage ss ;
            ss.__ss_family = 0 ;
            ],
            have_broken_ss_family=yes,
            have_broken_ss_family=no
          )
          AC_MSG_RESULT($have_broken_ss_family)
          if test x$have_broken_ss_family = xyes ; then
            AC_DEFINE(NEED_PREFIXED_SS_FAMILY, [],
            [Whether struct sockaddr::__ss_family exists])
            AC_DEFINE(ss_family, __ss_family,
            [ss_family is not defined here, use __ss_family instead])
          else
            AC_MSG_WARN(ss_family and __ss_family not found)
          fi
        fi

        have_gethostbyname2=no
        AC_CHECK_FUNC(gethostbyname2, have_gethostbyname2=yes)
        if test $have_gethostbyname2 = yes; then
          AC_DEFINE([HAVE_GETHOSTBYNAME2], [], [Define if gethostbyname2 can be used])
          AC_DEFINE([HAVE_IPV6], [], [Define if ipv6 can be used])
          HAVE_IPV6_SUPPORT="yes"
        else
          have_getipnodebyname=no
          AC_CHECK_FUNC(getipnodebyname, have_getipnodebyname=yes)
          if test $have_getipnodebyname = yes; then
            AC_DEFINE([HAVE_GETIPNODEBYNAME], [], [Define if getipnodebyname can be used])
            AC_DEFINE([HAVE_IPV6], [], [Define if ipv6 can be used])
            HAVE_IPV6_SUPPORT="yes"
          fi
        fi
      fi
    else
      AC_MSG_RESULT("no")
    fi
  fi
fi
LIBS="$old_LIBS"
AC_SUBST(NETPLAY_LIBS)

dnl ----- FFMPEG -----
FFMPEG_INCLUDES=

HAVE_FFMPEG=no
ffmpeg_use_header_subdirs=no

AC_MSG_CHECKING([for FFMPEG support])

dnl external ffmpeg
if test x"$enable_ffmpeg" = "xyes"; then
  PKG_PROG_PKG_CONFIG

  valid_ffmpeg_platform="no"

  if test x"$is_unix" = "xyes"; then
    dnl --- unix (requires dynlib support) ---
    if test x"$dynlib_support" = "xyes"; then
      valid_ffmpeg_platform="yes"
    fi
  else
    valid_ffmpeg_platform="yes"
  fi

  if test x"$valid_ffmpeg_platform" = "xyes"; then
    AC_MSG_RESULT([via pkg-config])
    PKG_CHECK_MODULES(FFMPEG_AV,  [libavcodec libavformat libavutil],
      [old_CFLAGS=$CFLAGS
       old_CPPFLAGS=$CPPFLAGS
       CFLAGS="$CFLAGS $FFMPEG_AV_CFLAGS"
       CPPFLAGS="$CPPFLAGS $FFMPEG_AV_CFLAGS"

       AC_CHECK_HEADER(libavformat/avformat.h,
        [AC_DEFINE([HAVE_FFMPEG_HEADER_SUBDIRS],,[FFMPEG uses subdirs for headers])
         ffmpeg_use_header_subdirs="yes"],
        [AC_CHECK_HEADER(avformat.h,,
          [AC_MSG_ERROR([No suitable FFMPEG header found!])])])

       CFLAGS=$old_CFLAGS
       CPPFLAGS=$old_CPPFLAGS

      PKG_CHECK_MODULES(FFMPEG_SWSCALE, [libswscale],
        [have_swscale=yes],
        [echo "no. trying img_convert"]
        [old_LIBS=$LIBS]
        [AC_CHECK_LIB(avcodec, img_convert,[have_imgconvert=yes])]
        [LIBS=$old_LIBS]
      )
      if (test x"${have_swscale}" = x"yes") || (test x"${have_imgconvert}" = x"yes") ; then
        AC_DEFINE([HAVE_FFMPEG],,[Have FFMPEG av* libs available])
        HAVE_FFMPEG_SUPPORT="yes"
        FFMPEG_INCLUDES="$FFMPEG_AV_CFLAGS"
        GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS ffmpegdrv.o ffmpeglib.o"
        dlopen_pthread=yes
      fi
      if (test x"${have_swscale}" = x"yes") ; then
        AC_DEFINE([HAVE_FFMPEG_SWSCALE],,[Have FFMPEG swscale lib available])
        HAVE_FFMPEG_SWSCALE_SUPPORT="yes"
        FFMPEG_INCLUDES="$FFMPEG_INCLUDES $FFMPEG_SWSCALE_CFLAGS"
        dlopen_pthread=yes
      fi
       ],
      [echo "no. disabled."]
    )
    AC_DEFINE([EXTERNAL_FFMPEG],,[External FFMPEG libraries are used])
    HAVE_FFMPEG=yes
    PKG_CHECK_MODULES(FFMPEG_SWRESAMPLE, [libswresample], [have_swresample=yes], [have_swresample=no])
    if test x"$have_swresample" = "xyes"; then
      AC_DEFINE([HAVE_FFMPEG_SWRESAMPLE],,[Have FFMPEG swresample lib available])
      HAVE_FFMPEG_SWRESAMPLE_SUPPORT="yes"
    else
      # dnl libav is abandoned and support should be removed, but check for it if swresample is missing.
      PKG_CHECK_MODULES(FFMPEG_AVRESAMPLE, [libavresample], [have_avresample=yes], [have_avresample=no])
      if test x"$have_avresample" = "xyes"; then
        AC_DEFINE([HAVE_FFMPEG_AVRESAMPLE],,[Have libav avresample lib available])
        HAVE_FFMPEG_AVRESAMPLE_SUPPORT="yes"
      else
        AC_MSG_ERROR([No swresample or avresample library available!])
      fi
    fi
  else
    AC_MSG_RESULT([not available])
  fi
fi

if test x"$HAVE_FFMPEG" = "xyes"; then

  dnl
  dnl After all that, is the version of ffmpeg compatible with our code.
  dnl ffmpeg 4.x is, ffmpeg 5 is not.
  dnl

  ORIG_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS $FFMPEG_INCLUDES"

  TEST_FFMPEG_C=" AVCodecContext *context_dropped_in_ffmpeg_5;
                  "

  if test x"$ffmpeg_use_header_subdirs" = "xyes"; then
    AC_TRY_COMPILE([ #include "libavformat/avformat.h" ],
                   [ $TEST_FFMPEG_C ],
                   ,
                   [ AC_MSG_ERROR([ffmpeg version is not compatible. Use 4.x]) ])
  else
    AC_TRY_COMPILE([ #include "avformat.h" ],
                   [ $TEST_FFMPEG_C ],
                   ,
                   [ AC_MSG_ERROR([ffmpeg version is not compatible. Use 4.x])])
  fi

  CFLAGS=$ORIG_CFLAGS
  AC_SUBST(FFMPEG_INCLUDES)
else
  AC_MSG_RESULT([disabled])
fi

dnl check for glibc 2.20+
linux_glibc_220_and_up=yes
AC_MSG_CHECKING(if we are using glibc-2.20 and up)
AC_TRY_LINK([#ifdef __linux
             #  include <ctype.h>
             #  ifdef __GLIBC__
             #    if (__GLIBC__>=2)
             #      if ((__GLIBC__==2 && __GLIBC_MINOR__>=20) || __GLIBC__>=3)
             #        error GLIBC2.20+
             #      endif
             #    endif
             #  endif
             #endif],
             [int a=0],
             linux_glibc_220_and_up=no)
AC_MSG_RESULT($linux_glibc_220_and_up)

dnl ----- Ethernet -----
TFE_LIBS=""
if test x"$enable_ethernet" = "xyes"; then
  have_tuntap="no"
  if test x"$is_win32" = "xyes"; then
    dnl We don't set TFE_LIBS here since we dynload the DLLs required on Windows
    dnl TODO: Maybe use AC_SEARCH_LIBS to support the npcap SDK headers?
    AC_CHECK_LIB(pcap, pcap_inject,[
      AC_DEFINE(HAVE_PCAP,,[Support for PCAP library.])
      AC_DEFINE(HAVE_RAWNET,,[Support for CS8900A ethernet controller.])
      HAVE_RAWNET_SUPPORT="yes";
      AC_DEFINE(HAVE_PCAP_INJECT,,[A libpcap version with pcap_inject is available])
    ],,$LIBS)
    AC_CHECK_LIB(pcap, pcap_sendpacket,[
      AC_DEFINE(HAVE_PCAP,,[Support for PCAP library.])
      AC_DEFINE(HAVE_RAWNET,,[Support for CS8900A ethernet controller.])
      HAVE_RAWNET_SUPPORT="yes";
      AC_DEFINE(HAVE_PCAP_SENDPACKET,,[A libpcap version with pcap_sendpacket is available])
    ],,$LIBS)
    if test x"$HAVE_RAWNET_SUPPORT" != "xyes"; then
      AC_MSG_ERROR([Ethernet support requested via --enable-ethernet, but the pcap headers were not found.])
    fi
  else
    dnl libpcap.a on Unix
    AC_CHECK_LIB(nsl, gethostbyname,[ LIBS="-lnsl $LIBS" ],,)
    AC_CHECK_LIB(socket, gethostbyname,[ LIBS="-lsocket $LIBS" ],,)
    AC_CHECK_LIB(pcap, pcap_inject,[
      AC_DEFINE(HAVE_PCAP,,[Support for PCAP library.])
      AC_DEFINE(HAVE_RAWNET,,[Support for CS8900A ethernet controller.])
      HAVE_RAWNET_SUPPORT="yes";
      AC_DEFINE(HAVE_PCAP_INJECT,,[A libpcap version with pcap_inject is available])
      TFE_LIBS="-lpcap"
    ],,$LIBS)
    AC_CHECK_LIB(pcap, pcap_sendpacket,[
      AC_DEFINE(HAVE_PCAP,,[Support for PCAP library.])
      AC_DEFINE(HAVE_RAWNET,,[Support for CS8900A ethernet controller.])
      HAVE_RAWNET_SUPPORT="yes";
      AC_DEFINE(HAVE_PCAP_SENDPACKET,,[A libpcap version with pcap_sendpacket is available])
      TFE_LIBS="-lpcap"
    ],,$LIBS)
    dnl libpcap.a
    dnl libnet.a
    AC_CHECK_LIB(pcap, pcap_open_live,[
      AC_CHECK_LIB(net, libnet_init,[
        AC_DEFINE(HAVE_PCAP,,[Support for PCAP library.])
        AC_DEFINE(HAVE_RAWNET,,[Support for CS8900A ethernet controller.])
        HAVE_RAWNET_SUPPORT="yes";
        AC_DEFINE(VICE_USE_LIBNET_1_1,,[Support for The Final Ethernet])
        TFE_LIBS="-lpcap `libnet-config --libs`"
        libnet_cflags="`libnet-config --defines`"
    ],,$LIBS)],,$LIBS)
    dnl libpcap.a
    dnl libnet.a
    AC_CHECK_LIB(pcap, pcap_open_live,[
      AC_CHECK_LIB(net, libnet_write_link_layer,[
        AC_DEFINE(HAVE_PCAP,,[Support for PCAP library.])
        AC_DEFINE(HAVE_RAWNET,,[Support for CS8900A ethernet controller.])
        HAVE_RAWNET_SUPPORT="yes";
        TFE_LIBS="-lpcap `libnet-config --libs`"
        libnet_cflags="`libnet-config --defines`"
    ],,$LIBS)],,$LIBS)
    if test x"$libnet_cflags" != "x"; then
      if test x"$linux_glibc_220_and_up" = "xyes"; then
        new_libnet_cflags=""
        for i in $libnet_cflags
        do
          if test x"$i" = "x-D_BSD_SOURCE"; then
            new_libnet_cflags="$new_libnet_cflags -D_DEFAULT_SOURCE"
          else
            new_libnet_cflags="$new_libnet_cflags $i"
          fi
        done
        CFLAGS="$CFLAGS $new_libnet_cflags"
      else
        CFLAGS="$CFLAGS $libnet_cflags"
      fi
    fi
    dnl check for tuntap
    AC_CHECK_HEADER(linux/if_tun.h,
                    [AC_DEFINE(HAVE_TUNTAP,,
                     [TUN/TAP support using <linux/if_tun.h>])
                     AC_DEFINE(HAVE_RAWNET,,[Support for CS8900A ethernet controller.])
                     have_tuntap=yes
                     HAVE_RAWNET_SUPPORT="yes"])
  fi
  if test x"$TFE_LIBS" = "x" -a x"$is_win32" = "xno" -a x"$is_win32_gtk3" = "xno" -a x"$have_tuntap" = "xno"; then
    AC_MSG_ERROR([Needed pcap library not found, please install libpcap-dev or equivalent])
  fi
fi
AC_SUBST(TFE_LIBS)

dnl ----- Sound Drivers -----
if test x"$is_unix" = "xyes" -a x"$is_unix_macosx" = "xno"; then
  if test x"$with_pulse" != "xno"; then
    AC_CHECK_HEADERS(pulse/simple.h,[AC_CHECK_LIB(pulse-simple, pa_simple_new,
                     [SOUND_DRIVERS="$SOUND_DRIVERS soundpulse.o";
                      SOUND_LIBS="$SOUND_LIBS -lpulse-simple -lpulse";
                      USE_PULSE_SUPPORT="yes";
                      AC_DEFINE(USE_PULSE,,[Enable pulseaudio support.])],,$SOUND_LIBS)])
    if test x"$with_pulse" != "xno" -a x"$USE_PULSE_SUPPORT" != "xyes"; then
      AC_MSG_ERROR([pulse audio support missing])
    fi
  fi

  dnl ALSA support checks
  if test x"$with_alsa" != "xno"; then
    AC_CHECK_HEADERS(alsa/asoundlib.h,[AC_CHECK_LIB(asound, snd_pcm_open,
                     [SOUND_DRIVERS="$SOUND_DRIVERS soundalsa.o";
                      SOUND_LIBS="$SOUND_LIBS -lasound";
                      USE_ALSA_SUPPORT="yes";
                      AC_DEFINE(USE_ALSA,,[Enable alsa support.])],,$SOUND_LIBS)])
    AC_CHECK_LIB(asound, snd_pcm_avail,
                 [AC_DEFINE(HAVE_SND_PCM_AVAIL,,[Use more accurate buffer fill reporting])])
    if test x"$with_alsa" != "xno" -a x"$USE_ALSA_SUPPORT" != "xyes"; then
      AC_MSG_ERROR([alsa support is missing])
    fi
  fi


  dnl OSS support checks
  dnl
  dnl For some reason 'sounduss.o' is actually correct. you'd expect soundoss.o
  dnl but that fails to compile
  dnl
  if test x"$with_oss" = "xyes"; then
    AC_CHECK_HEADERS(linux/soundcard.h machine/soundcard.h sys/soundcard.h soundcard.h,
                     [SOUND_DRIVERS="$SOUND_DRIVERS sounduss.o";
                      USE_OSS_SUPPORT="yes";
                      AC_DEFINE(USE_OSS,,[Enable oss support.])])
    AC_CHECK_LIB(ossaudio, _oss_ioctl,,,$SOUND_LIBS)
    if test x"$USE_OSS_SUPPORT" != "xyes"; then
      AC_MSG_ERROR([OSS support missing])
    fi
  fi

  dnl <sys/audioio.h> for sun / netbsd audio
  if test x"$with_sun" != "xno" -a x"$host_os" != "openbsd"; then
    AC_CHECK_HEADERS(sys/audioio.h,
                    [SOUND_DRIVERS="$SOUND_DRIVERS soundsun.o"; break])
  fi

fi


dnl --- Lame ---

if test x"$enable_lame" = "xyes" ; then

  old_CFLAGS="$CFLAGS"
  CFLAGS="$VICE_CFLAGS"

  AC_CHECK_HEADER(lame/lame.h,,)

  dnl the header is available!
  if test x"$ac_cv_header_lame_lame_h" = "xyes" ; then
    AC_MSG_CHECKING([for lame lib linking])
    if test x"$dynlib_support" = "xyes" -a x"$enable_static_lame" != "xyes" ; then
      dnl dynlib linking
      SOUND_DRIVERS="$SOUND_DRIVERS soundmp3.o lamelib.o"
      AC_DEFINE(USE_LAMEMP3,,[Enable lamemp3 support.])
      USE_LAMEMP3_SUPPORT="yes"
      AC_DEFINE(HAVE_EXTERNAL_LAME,,[External linking for lame libs])
      AC_MSG_RESULT([dynlib])
    else
      dnl try static linking
      AC_MSG_RESULT([trying static])
      AC_CHECK_LIB(mp3lame, lame_encode_buffer,[ADD_MPGDECODER=0],,)
      if test "$ac_cv_lib_mp3lame_lame_encode_buffer" = "no"; then
        unset ac_cv_lib_mp3lame_lame_encode_buffer
        AC_CHECK_LIB(mp3lame, lame_encode_buffer,[ADD_MPGDECODER=1],,[-lmpgdecoder])
      fi
      if test "$ac_cv_lib_mp3lame_lame_encode_buffer" != "no"; then
        SOUND_DRIVERS="$SOUND_DRIVERS soundmp3.o";
        SOUND_LIBS="$SOUND_LIBS -lmp3lame";
        if test "$ADD_MPGDECODER" = "1" ; then
          SOUND_LIBS="$SOUND_LIBS -lmpgdecoder";
        fi
        AC_DEFINE(USE_LAMEMP3,,[Enable lamemp3 support.])
        USE_LAMEMP3_SUPPORT="yes"
        AC_DEFINE(HAVE_STATIC_LAME,,[Static linking for lame libs])
      fi
      if test x"$USE_LAMEMP3_SUPPORT" != "xyes" -a x"$enable_lame" = "xyes"; then
        AC_MSG_ERROR([lame mp3 support is missing])
      fi
    fi
  else
    AC_MSG_ERROR([lame mp3 support is missing])
  fi

  CFLAGS="$old_CFLAGS"
fi

AC_PATH_PROGS(FCCACHE, fc-cache, false)
if test x"$FCCACHE" = "xfalse"; then
  AM_CONDITIONAL(HAVE_FC_CACHE, false)
else
  AM_CONDITIONAL(HAVE_FC_CACHE, true)
fi

dsound_header_no_lib="no"

if test x"$is_win32" = "xyes" -o x"$is_win32_gtk3" = "xyes"; then
    if test x"$enable_sdl1ui" != "xyes" -a x"$enable_sdl2ui" != "xyes"; then
        SOUND_DRIVERS="$SOUND_DRIVERS soundwmm.o"
        AC_MSG_CHECKING(whether we can use directx sound)
        AC_CHECK_HEADER(dsound.h,
              [ AC_DEFINE(USE_DXSOUND,,[Enable directx sound support.])
                USE_DXSOUND_SUPPORT="yes" ]
              [ SOUND_DRIVERS="$SOUND_DRIVERS sounddx.o" ]
              [ AC_MSG_CHECKING(for -ldsound) ]
              [ old_LIBS="$LIBS" ]
              [ LIBS="$LIBS -ldsound" ]
              [ AC_LINK_IFELSE([
                               AC_LANG_PROGRAM(
                                               [#define DIRECTSOUND_VERSION 0x500
                                                #include <dsound.h>],
                                               [LPDIRECTSOUNDBUFFER buffer=NULL;
                                                IDirectSoundBuffer_Restore(buffer);]
                                              )
                               ],
                            [ AC_DEFINE(HAVE_DSOUND_LIB, [], [dsound.lib or libdsound.a are present]) ]
                            [ AC_MSG_RESULT(yes) ]
                            [ SOUND_LIBS="$SOUND_LIBS -ldsound" ],
                            [ AC_MSG_RESULT(no) ]
                            [ dsound_header_no_lib="yes" ]
              )]
              [ LIBS="$old_LIBS" ]
        )

        if test x"$dsound_header_no_lib" = "xyes" -o x"$dinput_header_no_lib" = "xyes"; then
              AC_MSG_CHECKING(if CoInitialize can be linked)
              LIBS="$LIBS -lole32"
              AC_LINK_IFELSE([
                               AC_LANG_PROGRAM(
                                               [#include <objbase.h>],
                                               [CoInitialize(NULL);]
                                              )
                               ],
                               [ AC_MSG_RESULT(yes) ],
                               [ AC_MSG_ERROR(no) ]
                              )
        fi
    else
        SOUND_DRIVERS="$SOUND_DRIVERS soundwmm.o"
    fi
fi

dnl Do not remove (yet), for some reason these things are required even for
dnl SDL2 on Haiku.
if test x"$is_beos" = "xyes"; then
    SOUND_DRIVERS="$SOUND_DRIVERS soundbeos.o soundbsp.o"
fi


dnl Check for Ogg/Vorbis support
if test x"$with_vorbis" != "xyes"; then
    VORBIS_PRESENT=no
else
    VORBIS_PRESENT=yes
    AC_CHECK_HEADERS(vorbis/vorbisfile.h,,[VORBIS_PRESENT=no],)

    if test x"$VORBIS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(ogg, ogg_stream_flush,, [VORBIS_PRESENT=no])
    fi

    if test x"$VORBIS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(vorbis, vorbis_info_clear,, [VORBIS_PRESENT=no])
    fi

    if test x"$VORBIS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(vorbisfile, ov_open_callbacks,, [VORBIS_PRESENT=no])
    fi

    if test x"$VORBIS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(vorbisenc, vorbis_encode_init_vbr,, [VORBIS_PRESENT=no])
    fi

    if test x"$with_vorbis" = "xyes" -a x"$VORBIS_PRESENT" = "xno"; then
        AC_MSG_ERROR([Ogg/Vorbis requested but missing.])
    fi
    dnl Where does soundvorbis.o come from?
    SOUND_DRIVERS="$SOUND_DRIVERS soundvorbis.o";
    LIBS="$LIBS -lvorbisfile -logg -lvorbis -lvorbisenc"
    USE_VORBIS_SUPPORT="yes"
    AC_DEFINE(USE_VORBIS,,[Enable ogg/vorbis support.])
fi


dnl Check FLAC support
if test x"$with_flac" != "xyes"; then
    FLAC_PRESENT=no
else
    FLAC_PRESENT=yes

    AC_CHECK_HEADERS(FLAC/stream_decoder.h,,[FLAC_PRESENT=no],)

    if test x"$FLAC_PRESENT" = "xyes"; then
        AC_CHECK_LIB(FLAC, FLAC__stream_decoder_get_channels,, [FLAC_PRESENT=no])
    fi

    if test x"$FLAC_PRESENT" = "xno"; then
        unset ac_cv_lib_FLAC_FLAC__stream_decoder_get_channels
        dnl Windows-specific check:
        AC_CHECK_LIB(FLAC, FLAC__stream_decoder_get_channels,, [FLAC_PRESENT=no], [-lwinmm])
        if test x"$FLAC_PRESENT" = "xyes"; then
            LIBS="$LIBS -lwinmm"
        fi
    fi

    if test x"$FLAC_PRESENT" = "xno"; then
        AC_MSG_ERROR([FLAC support requested, but missing.])
    fi
    LIBS="$LIBS -lFLAC"
    SOUND_DRIVERS="$SOUND_DRIVERS soundflac.o"
    USE_FLAC_SUPPORT="yes"
    AC_DEFINE(USE_FLAC,,[Enable FLAC support.])

fi


if test x"$is_unix_macosx" = "xyes"; then

  dnl --- check for CoreAudio ---
  AC_CHECK_HEADER(CoreAudio/CoreAudio.h,,)
  if test x"$ac_cv_header_CoreAudio_CoreAudio_h" = "xyes" ; then
    AC_CHECK_HEADER(AudioToolbox/AudioToolbox.h,,)
    if test x"$ac_cv_header_AudioToolbox_AudioToolbox_h" = "xyes" ; then
      AC_MSG_CHECKING(whether we can link the CoreAudio framework)
      old_LIBS="${LIBS}"
      LIBS="${LIBS} -framework CoreAudio -framework AudioToolbox"
      AC_TRY_LINK([#include <CoreAudio/CoreAudio.h>],
                  [AudioDeviceStart(0,0);],
                  [AC_MSG_RESULT(yes);
                   SOUND_DRIVERS="$SOUND_DRIVERS soundcoreaudio.o";
                   SOUND_LIBS="$SOUND_LIBS -framework CoreAudio -framework AudioToolbox";
                   USE_COREAUDIO_SUPPORT="yes";
                   AC_DEFINE(USE_COREAUDIO,,[Enable CoreAudio support.])],
                  [AC_MSG_RESULT(no)])
      LIBS=${old_LIBS}

      AC_CHECK_HEADER(AudioUnit/AudioUnit.h,,)
      if test x"$ac_cv_header_AudioUnit_AudioUnit_h" = "xyes" ; then
        AC_MSG_CHECKING(whether we can link the AudioUnit framework)
        old_LIBS="${LIBS}"
        LIBS="${LIBS} -framework AudioUnit"
        AC_TRY_LINK([#include <AudioUnit/AudioUnit.h>],
                    [AudioOutputUnitStart(NULL);],
                    [AC_MSG_RESULT(yes);
                     SOUND_LIBS="$SOUND_LIBS -framework AudioUnit";
                     HAVE_AUDIO_UNIT_SUPPORT="yes";
                     AC_DEFINE(HAVE_AUDIO_UNIT,,[Enable AudioUnit support.])],
                    [AC_MSG_RESULT(no)])
        LIBS=${old_LIBS}
      fi
    fi
  fi

  dnl --- check for CoreMIDI ---
  if test x"$enable_midi" = "xyes"; then
    AC_MSG_CHECKING(whether we can link the CoreMIDI framework)
    old_LIBS="${LIBS}"
    LIBS="$LIBS -framework CoreMidi -framework CoreServices"
    AC_TRY_LINK([#include <CoreMIDI/MIDIServices.h>],
                [MIDIGetNumberOfDevices()],
                [AC_MSG_RESULT(yes);
                 AC_DEFINE(HAVE_MIDI,,[Enable MIDI emulation.])
                 HAVE_MIDI_SUPPORT="yes"],
               [AC_MSG_RESULT(no);
                 LIBS=${old_LIBS}])
  fi
  if test x"$enable_midi" = "xyes" -a x"$HAVE_MIDI_SUPPORT" != "xyes"; then
    AC_MSG_ERROR([MIDI support missing])
  fi
fi

AC_SUBST(SOUND_DRIVERS)
AC_SUBST(SOUND_LIBS)

dnl Check for ParSID/SSI2001/HardSID/CW support
if test x"$is_unix" = "xyes"; then

  dnl Check cpu first
  case "$host_cpu" in
  i*86 | x86_64* | amd64*)
      ;;
  *)
      enable_parsid=no
      enable_ssi2001=no
      enable_hardsid=no
      enable_catweasel=no
      ;;
  esac

  if test x"$enable_parsid" = "xyes" -o x"$enable_ssi2001" = "xyes" -o x"$enable_hardsid" != "xno" -o x"$enable_catweasel" = "xyes"; then

    if test x"$enable_libieee1284" = "xyes"; then
      LIBIEEE1284_HEADERS_PRESENT=yes
    else
      LIBIEEE1284_HEADERS_PRESENT=no
    fi
    LINUX_HARDSID_HEADER_PRESENT=yes
    LINUX_PARPORT_HEADERS_PRESENT=yes
    CATWEASEL_HEADER_PRESENT=yes
    BSD_SET_IOPERM_HEADERS_PRESENT=yes
    PARSID_SUPPORT=no
    IOSID_SUPPORT=no
    PORTSID_SUPPORT=no
    PCIUTILS_HEADER_PRESENT=yes
    PCIUTILS_LIB_PRESENT=no

    dnl Check for needed io headers
    if test x"$enable_libieee1284" = "xyes"; then
      AC_CHECK_HEADERS(ieee1284.h,,[LIBIEEE1284_HEADERS_PRESENT=no],)
    fi
    AC_CHECK_HEADERS(linux/hardsid.h,,[LINUX_HARDSID_HEADER_PRESENT=no],)
    AC_CHECK_HEADERS(linux/ppdev.h linux/parport.h,,[LINUX_PARPORT_HEADERS_PRESENT=no],)
    AC_CHECK_HEADERS(dev/ppbus/ppi.h dev/ppbus/ppbconf.h,,[FREEBSD_PARPORT_HEADERS_PRESENT=no],)
    AC_CHECK_HEADERS(cwsid.h,,[CATWEASEL_HEADER_PRESENT=no],)
    AC_CHECK_HEADERS(machine/sysarch.h,,[BSD_SET_IOPERM_HEADERS_PRESENT=no],)
    AC_CHECK_HEADERS(unistd.h sys/io.h machine/pio.h machine/cpufunc.h)
    AC_CHECK_HEADERS(pci/pci.h,,[PCIUTILS_HEADER_PRESENT=no],)

    if test x"$PCIUTILS_HEADER_PRESENT" = "xyes"; then
      AC_CHECK_LIB(pciutils, pci_fill_info,[LIBS="-lpciutils $LIBS"; PCIUTILS_LIB_PRESENT=yes],,)
      if test x"$PCIUTILS_LIB_PRESENT" = "xno"; then
        AC_CHECK_LIB(pci, pci_fill_info,[LIBS="-lpci $LIBS"; PCIUTILS_LIB_PRESENT=yes],,)
      fi
      if test x"$PCIUTILS_LIB_PRESENT" != "xno"; then
        AC_DEFINE(HAVE_LIBPCI,,[Define to 1 if you have the 'pciutils' library.])
        HAVE_PCIUTILS_SUPPORT=yes
      fi
    fi

    if test x"$LIBIEEE1284_HEADERS_PRESENT" = "xyes"; then
      AC_CHECK_LIB(ieee1284, ieee1284_find_ports,[LIBS="-lieee1284 $LIBS"; PARSID_SUPPORT=yes],,)
      if test x"$PARSID_SUPPORT" = "xyes"; then
        AC_DEFINE(HAVE_LIBIEEE1284,
                  [Define to 1 if you have the 'ieee1284' library (-lieee1284).])
        HAVE_LIBIEEE1284_SUPPORT="yes"
      else
        AC_MSG_ERROR([libieee1284 is missing])
      fi
    else
      if test x"$enable_libieee1284" = "xyes"; then
        AC_MSG_ERROR([libieee1284 header is missing])
      fi
    fi

    if test x"$PARSID_SUPPORT" != "xno" -a x"$enable_ssi2001" = "xno" -a x"$enable_hardsid" = "xno"; then
      IOSID_SUPPORT=yes
      HAVE_IOSID_SUPPORT=yes
    fi

    if test x"$LINUX_PARPORT_HEADERS_PRESENT" = "xyes"; then
      AC_DEFINE(HAVE_LINUX_PARPORT_HEADERS,,[Support for Linux par port device file.])
      PORTSID_SUPPORT=yes
      HAVE_PORTSID_SUPPORT=yes
    fi

    if test x"$FREEBSD_PARPORT_HEADERS_PRESENT" = "xyes"; then
      AC_DEFINE(HAVE_FREEBSD_PARPORT_HEADERS,,[Support for FreeBSD par port device file.])
      PORTSID_SUPPORT=yes
      HAVE_PORTSID_SUPPORT=yes
    fi

    if test x"$IOSID_SUPPORT" = "xno"; then
      if test x"$BSD_SET_IOPERM_HEADERS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(amd64, amd64_set_ioperm,[LIBS="-lamd64 $LIBS"; IOSID_SUPPORT=yes],,)
        if test x"$IOSID_SUPPORT" = "xyes"; then
          AC_DEFINE(HAVE_LIBAMD64,,
                    [Define to 1 if you have the 'amd64' library (-lamd64).])
        fi
      fi
    fi

    if test x"$IOSID_SUPPORT" = "xno"; then
      if test x"$BSD_SET_IOPERM_HEADERS_PRESENT" = "xyes"; then
        AC_CHECK_LIB(i386, i386_get_ioperm,[LIBS="-li386 $LIBS"],,)
        AC_CHECK_FUNCS(i386_set_ioperm,[IOSID_SUPPORT=yes],)
      fi
    fi

    if test x"$IOSID_SUPPORT" = "xno"; then
      AC_CHECK_FUNCS(ioperm,[IOSID_SUPPORT=yes],)
      AC_CHECK_FUNCS(inb outb outb_p inb_p inbv outbv)
    fi

    if test x"$IOSID_SUPPORT" = "xyes"; then
      if test x"$enable_parsid" = "xyno"; then
        AC_DEFINE(HAVE_PARSID,,[Support for ParSID.])
        AM_CONDITIONAL(HAVE_PARSID, true)
        HAVE_PARSID_SUPPORT="yes"
      fi
      if test x"$enable_ssi2001" = "xyes"; then
        AC_DEFINE(HAVE_SSI2001,,[Support for SSI2001 (ISA SID card).])
        AM_CONDITIONAL(HAVE_SSI2001, true)
        HAVE_SSI2001_SUPPORT="yes"
      fi
      if test x"$enable_catweasel" = "xyes"; then
        AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
        AC_DEFINE(HAVE_CATWEASELMKIII_IO,,[Support for direct PCI I/O access Catweasel MKIII.])
        AM_CONDITIONAL(HAVE_CATWEASELMKIII, true)
        HAVE_CATWEASELMKIII_SUPPORT="yes"
      fi
      if test x"$enable_hardsid" != "xno"; then
        AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
        AC_DEFINE(HAVE_HARDSID_IO,,[Support for PCI/ISA HardSID.])
        HAVE_HARDSID_SUPPORT="yes"
      fi
    else
      if test x"$enable_hardsid" != "xno" -a x"$LINUX_HARDSID_HEADER_PRESENT" = "xyes"; then
        AC_DEFINE(HAVE_HARDSID,,[Support for HardSID.])
        HAVE_HARDSID_SUPPORT="yes"
      fi
      if test x"$enable_catweasel" = "xyes" -a x"$CATWEASEL_HEADER_PRESENT" = "xyes"; then
        AC_DEFINE(HAVE_CATWEASELMKIII,,[Support for Catweasel MKIII.])
        AM_CONDITIONAL(HAVE_CATWEASELMKIII, true)
        HAVE_CATWEASELMKIII_SUPPORT="yes"
      fi
    fi

    if test x"$PORTSID_SUPPORT" = "xyes"; then
      if test x"$enable_parsid" = "xyes" -a x"HAVE_PARSID_SUPPORT" != "xyes"; then
        AC_DEFINE(HAVE_PARSID,,[Support for ParSID.])
        AM_CONDITIONAL(HAVE_PARSID, true)
        AC_DEFINE(HAVE_PORTSID,,[Support for file device based access to ParSID.])
        HAVE_PARSID_SUPPORT="yes"
      fi
    fi

    if test x"$enable_catweasel" = "xyes" -a x"$HAVE_CATWEASELMKIII_SUPPORT" != "xyes"; then
      AC_MSG_ERROR([CatWeaselMKIII support is missing])
    fi

    if test x"$enable_hardsid" = "xyes" -a x"$HAVE_HARDSID_SUPPORT" != "xyes"; then
      AC_MSG_ERROR([HardSID support is missing])
    fi

  fi
fi

AC_TYPE_SIGNAL
AC_FUNC_VFORK
AC_CHECK_TYPES(u_short)
AC_CHECK_TYPES(socklen_t, [], [], [[#include <sys/socket.h>]])
dnl POSIX provides off_t by including <stdio.h>, but on Windows we have to
dnl include <sys/types.h>
AC_CHECK_TYPES(off_t)
AC_CHECK_TYPES(off_t,
               [AC_DEFINE(HAVE_OFF_T_IN_SYS_TYPES,,[Include sys/types.h for off_t])],
               [],
               [[#include <sys/types.h>]])

dnl some platforms have some of the functions in libbsd,
dnl so we check it out first.
AC_CHECK_LIB(bsd,gettimeofday,,,$LIBS)

dnl some platforms have some of the functions in libposix,
dnl so we check it out second.
AC_CHECK_LIB(posix,gettimeofday,,,$LIBS)

AC_CHECK_FUNCS(gettimeofday memmove atexit strerror strcasecmp strncasecmp dirname mkstemp swab getcwd getpwuid random rewinddir strtok strtok_r strtoul snprintf vsnprintf ltoa ultoa stpcpy strlcpy strlwr strrev fseeko ftello _fseeki64 _ftelli64)
AC_CHECK_FUNCS(strdup, [have_strdup_func=yes], [have_strdup_func=no])

if test x"$have_strdup_func" = "xno"; then
  AC_MSG_CHECKING(whether strdup is defined as a macro)
  AC_TRY_LINK([#include <string.h>],
               [char *something = strdup("something")],
               [AC_MSG_RESULT(yes); have_strdup_func=yes],
               [AC_MSG_RESULT(no); have_strdup_func=no])

  if test x"$have_strdup_func" = "xyes"; then
    AC_DEFINE(HAVE_STRDUP,,[Define to 1 if you have the 'strdup' function.])
  fi
fi

AC_SUBST(LIBS)


AC_CHECK_FUNC(nanosleep,
              [ AC_DEFINE(HAVE_NANOSLEEP,,[Use nanosleep instead of usleep]) ])

dnl Check time.h.

dnl AC_HEADER_TIME
dnl AC_STRUCT_TM

dnl GTK3-FIXME: check if readline is even needed for GTK3 UI and disable the check if needed

dnl ----- Readline -----
dnl Check whether we have GNU readline.  If not, use our replacement.
dnl The user can force us to use the replacement with '--without-readline'.
READLINE_LIBS=
EDITLINE_LIBS=
if test x"$is_unix_x11" = "xyes"; then
  if test x"$with_readline" != "xno" ; then
    READLINE_HEADER_PRESENT=yes
    AC_CHECK_HEADERS(readline/readline.h,,[READLINE_HEADER_PRESENT=no],)
    READLINE=""
    unset ac_cv_lib_readline_readline
    old_LIBS="$LIBS"
    AC_CHECK_LIB(readline, readline,
               [ READLINE="" READLINE_LIBS="-lreadline"],
               [],,)

    if test "$ac_cv_lib_readline_readline" = "no"; then
      unset ac_cv_lib_readline_readline
      AC_CHECK_LIB(readline, readline,
               [ READLINE="" READLINE_LIBS="-lreadline -ltermcap"],
               [], [-ltermcap],)
    fi

    if test "$ac_cv_lib_readline_readline" = "no"; then
      unset ac_cv_lib_readline_readline
      AC_CHECK_LIB(readline, readline,
               [ READLINE="" READLINE_LIBS="-lreadline -lncurses"],
               [], [-lncurses],)
    fi

    if test "$ac_cv_lib_readline_readline" = "no"; then
      unset ac_cv_lib_readline_readline
      AC_CHECK_LIB(readline, readline,
             [ READLINE="" READLINE_LIBS="-lreadline -lcurses"],
             [ ],
              [-lcurses],)
    fi

    if test x"$enable_sdl1ui" != "xno" -o x"$enable_sdl2ui" != "xno"; then
      READLINE=""
    fi

    if test "$ac_cv_lib_readline_readline" = "yes"; then
      AC_CHECK_LIB(readline, rl_readline_name,
             [ AC_DEFINE(HAVE_RLNAME,,
             [Does the 'readline' library support 'rl_readline_name'?]) ],,)
    fi
    LIBS="${old_LIBS}"
  else
    if test x"$enable_sdl1ui" != "xyes" -a x"$enable_sdl2ui" != "xyes"; then
      READLINE="\$(top_builddir)/src/arch/unix/readline/libreadline.a"
    fi
  fi
else
  READLINE=""
fi
AM_CONDITIONAL(NEED_READLINE, test x"$READLINE" != "x")
AC_SUBST(READLINE)
AC_SUBST(READLINE_LIBS)

dnl Configure graphics output drivers
old_LIBS="$LIBS"
GFXOUTPUT_LIBS=

dnl check for png support
if test x"$with_png" != "xno" ; then
  dnl Check for the PNG library.
  AC_CHECK_HEADER(png.h,,)
  if test x"$ac_cv_header_png_h" = "xyes" ; then
    unset ac_cv_lib_png_png_sig_cmp
    AC_CHECK_LIB(png, png_sig_cmp,
                 [ GFXOUTPUT_LIBS="-lpng $GFXOUTPUT_LIBS";
                   GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS pngdrv.o";
                   HAVE_PNG_SUPPORT="yes";
                   AC_DEFINE(HAVE_PNG,,[Can we use the PNG library?]) ],,)
    if test "$ac_cv_lib_png_png_sig_cmp" = "no"; then
      unset ac_cv_lib_png_png_sig_cmp
      AC_CHECK_LIB(png, png_sig_cmp,
                   [ GFXOUTPUT_LIBS="-lpng -lz $GFXOUTPUT_LIBS";
                     GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS pngdrv.o";
                     HAVE_PNG_SUPPORT="yes";
                     AC_DEFINE(HAVE_PNG,,
                               [Can we use the PNG library?]) ],,"-lz")
    fi
  fi

  if test x"$HAVE_PNG_SUPPORT" != "xyes" -a x"$cross_compiling" != "xyes"; then
    PKG_PROG_PKG_CONFIG
    if test x"$PKG_CONFIG" != "x"; then
      AC_MSG_CHECKING([if pkgconfig libpng is present])
      PKG_CHECK_MODULES(PNG, [libpng], HAVE_PNG_SUPPORT="yes")
      if test x"$HAVE_PNG_SUPPORT" = "xyes"; then
          GFXOUTPUT_LIBS="$PNG_LIBS $GFXOUTPUT_LIBS"
          GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS pngdrv.o";
          VICE_CFLAGS="$VICE_CFLAGS $PNG_CFLAGS";
          AC_DEFINE(HAVE_PNG,,[Can we use the PNG library?])
          AC_MSG_RESULT([yes])
      else
          AC_MSG_RESULT([no])
      fi
    fi
  fi

  if test x"$HAVE_PNG_SUPPORT" != "xyes"; then
    AC_MSG_ERROR([PNG support is missing])
  fi
fi

dnl Check for the GIF or UNGIF library.
if test x"$with_gif" = "xyes"; then
  AC_CHECK_HEADER(gif_lib.h,,)
  if test x"$ac_cv_header_gif_lib_h" = "xyes" ; then
    AC_CHECK_LIB(ungif, EGifPutLine, [
                 GFXOUTPUT_LIBS="-lungif $GFXOUTPUT_LIBS";
                 GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS gifdrv.o";
                 HAVE_GIF_SUPPORT="yes";
                 AC_DEFINE(HAVE_GIF,,[Can we use the GIF or UNGIF library?]) ],,)
    if test "$ac_cv_lib_ungif_EGifPutLine" = "no"; then
      AC_CHECK_LIB(gif, EGifPutLine, [
                   GFXOUTPUT_LIBS="-lgif $GFXOUTPUT_LIBS";
                   GFXOUTPUT_DRIVERS="$GFXOUTPUT_DRIVERS gifdrv.o";
                   HAVE_GIF_SUPPORT="yes";
                   AC_DEFINE(HAVE_GIF,,[Can we use the GIF or UNGIF library?]) ],,)
    fi
 fi
 if test x"$HAVE_GIF_SUPPORT" != "xyes"; then
   AC_MSG_ERROR([GIF support not present])
 fi
fi


LIBS="$old_LIBS"
AC_SUBST(GFXOUTPUT_DRIVERS)
AC_SUBST(GFXOUTPUT_LIBS)

AC_SUBST(JOYSTICK_DRIVERS)

dnl PortAudio support checks

if test x"$enable_portaudio" != "xno"; then
  AC_CHECK_HEADERS(portaudio.h, PA_HEADERS="yes", PA_HEADERS="no")

  if test x"$PA_HEADERS" = "xyes"; then
    if test x"$is_win32" = "xyes" -o x"$is_win32_gtk3" = "xyes"; then
      AC_CHECK_LIB(portaudio, Pa_Initialize,
                   [LIBS="$LIBS -lportaudio -lwinmm";
                    USE_PORTAUDIO_SUPPORT="yes";
                    AC_DEFINE(USE_PORTAUDIO,,[Enable portaudio sampling support.])],,-lwinmm)
    else
      AC_CHECK_LIB(portaudio, Pa_Initialize,
                 [LIBS="$LIBS -lportaudio";
                  USE_PORTAUDIO_SUPPORT="yes";
                  AC_DEFINE(USE_PORTAUDIO,,[Enable portaudio sampling support.])],,)
    fi
  fi

  if test x"$enable_portaudio" = "xyes" -a x"$USE_PORTAUDIO_SUPPORT" != "xyes"; then
    AC_MSG_ERROR([PortAudio support is missing])
  fi
fi

dnl Check MP3 decoding support
if test x"$with_mpg123" = "xyes"; then
    AC_CHECK_HEADERS(mpg123.h,[AC_CHECK_LIB(mpg123, mpg123_init,
                     [LIBS="$LIBS -lmpg123";
                     USE_MPG123_SUPPORT="yes";
                     AC_DEFINE(USE_MPG123,,[Enable mpg123 mp3 decoding support.])],,)])
    if test x"$USE_MPG123_SUPPORT" != "xyes"; then
        AC_MSG_ERROR([MPG123 support requested but missing])
    fi
fi

dnl Check for libraries and header files
if test x"$is_beos" = "xyes"; then

  dnl On BEOS, we already know what we want.

  LIBS="$LIBS -lbe -ltracker -ldevice -lmedia -lgame"
  dnl AC_SUBST(LDFLAGS)
fi

dnl CBM4Linux/OpenCBM
AC_MSG_CHECKING([for OpenCBM support])
if test x"$enable_realdevice" != "xno"; then
  if test x"$is_win32" = "xyes"; then
    AC_DEFINE(HAVE_REALDEVICE,,[Support for OpenCBM (former CBM4Linux).])
    HAVE_REALDEVICE_SUPPORT="yes"
    AM_CONDITIONAL(HAVE_REALDEVICE, true)
    AC_MSG_RESULT([yes])
  else
    if test x"$dynlib_support" = "xyes"; then
      if test x"$is_beos" != "xyes"; then
        AC_DEFINE(HAVE_REALDEVICE,,[Support for OpenCBM (former CBM4Linux).])
        HAVE_REALDEVICE_SUPPORT="yes"
        AM_CONDITIONAL(HAVE_REALDEVICE, true)
        AC_MSG_RESULT([yes])
      else
        AM_CONDITIONAL(HAVE_REALDEVICE, false)
        AC_MSG_RESULT([no (not supported on current host)])
      fi
    else
      AM_CONDITIONAL(HAVE_REALDEVICE, false)
      AC_MSG_RESULT([no (dynamic lib support missing)])
    fi
  fi
else
  AM_CONDITIONAL(HAVE_REALDEVICE, false)
  AC_MSG_RESULT([no (realdevice disabled)])
fi

AC_SUBST(VICE_CPPFLAGS)
AC_SUBST(VICE_CFLAGS)
AC_SUBST(VICE_CXXFLAGS)
AC_SUBST(VICE_LDFLAGS)

if test x"$is_unix_macosx" = "xyes"; then
  dnl For now, OBJCFLAGS is the same as CFLAGS
  VICE_OBJCFLAGS="$VICE_CFLAGS $OBJCFLAGS"
  AC_SUBST(VICE_OBJCFLAGS)
fi

AC_SUBST(vsid_LDFLAGS)
AC_SUBST(x64_LDFLAGS)
AC_SUBST(x128_LDFLAGS)
AC_SUBST(xscpu64_LDFLAGS)
AC_SUBST(xvic_LDFLAGS)
AC_SUBST(xpet_LDFLAGS)
AC_SUBST(xplus4_LDFLAGS)
AC_SUBST(xcbm2_LDFLAGS)


dnl Do we need to build x64?
if test x"$enable_x64" = "xyes"; then
  X64_INCLUDED="yes"
  AM_CONDITIONAL(SUPPORT_X64, true)
else
  AM_CONDITIONAL(SUPPORT_X64, false)
  X64_INCLUDED="no"
fi


dnl Setup the system-specific object files.
AM_CONDITIONAL(USE_SDLUI, false)
AM_CONDITIONAL(USE_SDL2UI, false)
if test x"$enable_sdl1ui" = "xyes" -o x"$enable_sdl2ui" = "xyes"; then
  ARCH_DIR="\$(top_builddir)/src/arch/sdl"
  ARCH_SRC_DIR="\$(top_srcdir)/src/arch/sdl"
  ARCH_LIBS="$ARCH_DIR/libarch.a"
  ARCH_INCLUDES="-I$ARCH_SRC_DIR -I\$(top_srcdir)/src/arch/shared"
  if test x"$ac_cv_lib_readline_readline" = "xyes"; then
    AC_DEFINE(HAVE_READLINE,,[Enable the readline library])
  fi
  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"

  if test x"$enable_sdl2ui" = "xyes"; then
    AM_CONDITIONAL(USE_SDL2UI, true)
    SDLCONFIG="$sdl2_config"
  else
    AM_CONDITIONAL(USE_SDLUI, true)
    SDLCONFIG="$sdl_config"
  fi
  AC_SUBST(SDLCONFIG)
fi

SDL_EXTRA_LIBS=""

AM_CONDITIONAL(MAKE_INSTALL, true)
AM_CONDITIONAL(MAKE_BINDIST, false)


dnl
dnl Set up X64 image support
dnl
if test x"$enable_x64_image" = "xyes"; then
  HAVE_X64_IMAGE_SUPPORT="yes"
  AM_CONDITIONAL(HAVE_X64_IMAGE, true)
  AC_DEFINE(HAVE_X64_IMAGE,,[Support X64 images])
else
  AM_CONDITIONAL(HAVE_X64_IMAGE, false)
fi


if test x"$enable_gtk3ui" = "xyes"; then
  dnl Use C++ compiler/linker since novte uses C++
  LINKCC='$(CXX)'
  ARCH_DIR="\$(top_builddir)/src/arch/gtk3"
  ARCH_SRC_DIR="\$(top_srcdir)/src/arch/gtk3"
  ARCH_LIBS="$ARCH_DIR/libarch.a $ARCH_DIR/widgets/libwidgets.a $ARCH_DIR/widgets/base/libbasewidgets.a $ARCH_DIR/novte/libnovte.a $ARCH_DIR/joystickdrv/libjoystickdrv.a"
  if test x"$is_win32" = "xyes" -o x"$is_win32_gtk3" = "xyes"; then
    ARCH_INCLUDES="-I$ARCH_SRC_DIR -I\$(top_srcdir)/src/arch/shared -I\$(top_srcdir)/src/arch/mingw32-pcap/wpcap"
    AM_CONDITIONAL(MAKE_INSTALL, false)
    AM_CONDITIONAL(MAKE_BINDIST, true)
  else
    ARCH_INCLUDES="-I$ARCH_SRC_DIR -I\$(top_srcdir)/src/arch/shared -I\$(top_srcdir)/src/arch"
  fi
  if test x"$ac_cv_lib_readline_readline" = "xyes"; then
    AC_DEFINE(HAVE_READLINE,,[Enable the readline library])
  fi
  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"

  AM_CONDITIONAL(USE_GTK3UI, true)

else
  AM_CONDITIONAL(USE_GTK3UI, false)
fi


# WINDRES_LIB is used to link some Windows resource file to Windows binaries
# It's not longer used by Gtk3, that uses its own per-emu files, so right now it's
# only used for SDL. But the Gtk3 Windows .res files should also be used for SDL
# on Windows, which means moving around some autotools stuff.
#
# For now though, let's keep this intact. -- compyx
#
if test x"$enable_sdl" = "xyes" -o x"$enable_sdl2ui" = "xyes"; then
  WINDRES_LIB="$ARCH_DIR/icon.res"
else
  WINDRES_LIB=""
fi


if test x"$enable_headlessui" = "xyes"; then
  ARCH_DIR="\$(top_builddir)/src/arch/headless"
  ARCH_SRC_DIR="\$(top_srcdir)/src/arch/headless"
  ARCH_LIBS="$ARCH_DIR/libarch.a"
  if test x"$is_win32" = "xyes"; then
    ARCH_INCLUDES="-I$ARCH_SRC_DIR -I\$(top_srcdir)/src/arch/shared -I\$(top_srcdir)/src/arch/mingw32-pcap/wpcap"
    AM_CONDITIONAL(MAKE_INSTALL, false)
    AM_CONDITIONAL(MAKE_BINDIST, true)
  else
    ARCH_INCLUDES="-I$ARCH_SRC_DIR -I\$(top_srcdir)/src/arch/shared -I\$(top_srcdir)/src/arch"
  fi
  if test x"$ac_cv_lib_readline_readline" = "xyes"; then
    AC_DEFINE(HAVE_READLINE,,[Enable the readline library])
  fi
  AC_DEFINE(HAVE_MOUSE,,[Enable 1351 mouse support])
  HAVE_MOUSE_SUPPORT="yes"
  AC_DEFINE(HAVE_LIGHTPEN,,[Enable lightpen support])
  HAVE_LIGHTPEN_SUPPORT="yes"

  AM_CONDITIONAL(USE_HEADLESSUI, true)
else
  AM_CONDITIONAL(USE_HEADLESSUI, false)
fi

if test x"$is_unix" = "xyes"; then

  if test x"$is_win32_gtk3" = "xyes"; then
    AC_DEFINE(WINDOWS_COMPILE,,[Are we compiling for windows?])
    LIBS="$LIBS -lntdll"
  else
    AC_DEFINE(UNIX_COMPILE,,[Are we compiling for unix?])
  fi

  AM_CONDITIONAL(UNIX_COMPILE, true)
  if test x"$is_win32_gtk3" = "xyes"; then
     AM_CONDITIONAL(WINDOWS_COMPILE, true)
  else
     AM_CONDITIONAL(WINDOWS_COMPILE, false)
  fi

  if test x"$is_unix_macosx" = "xyes" ; then
    AM_CONDITIONAL(MACOS_COMPILE, true)
    dnl macOS supports both make install and make bindist
    AM_CONDITIONAL(MAKE_BINDIST, true)
  else
    AM_CONDITIONAL(MACOS_COMPILE, false)
  fi


elif test x"$is_win32" = "xyes"; then
  AC_DEFINE(WINDOWS_COMPILE,,[Are we compiling for win32?])

  if test x"$enable_sdl1ui" = "xyes" -o x"$enable_sdl2ui" = "xyes"; then
    if test x"$host_cpu" = "xx86_64" -o x"$host_cpu" = "xamd64"; then
      SDL_EXTRA_LIBS="$UI_LIBS -lwinmm -lws2_32"
    else
      SDL_EXTRA_LIBS="$UI_LIBS -lwinmm -lwsock32"
    fi
  fi

  AM_CONDITIONAL(WINDOWS_COMPILE, true)
  AM_CONDITIONAL(UNIX_COMPILE, false)
  AM_CONDITIONAL(MACOS_COMPILE, false)
  AM_CONDITIONAL(MAKE_INSTALL, false)
  AM_CONDITIONAL(MAKE_BINDIST, true)
elif test x"$is_beos" = "xyes"; then
  AM_CONDITIONAL(UNIX_COMPILE, false)
  AM_CONDITIONAL(WINDOWS_COMPILE, false)
  AM_CONDITIONAL(MACOS_COMPILE, false)
  AM_CONDITIONAL(MAKE_INSTALL, false)
  AM_CONDITIONAL(MAKE_BINDIST, true)
else
  AC_MSG_WARN([No architecture defined!])
fi

dnl Check wether we have gcc
if test x"$GCC" = "xyes" ; then
  AC_DEFINE(USE_GCC,, [Define when using gcc] )
fi


AC_SUBST(HAVE_READLINE)
AC_SUBST(ARCH_INCLUDES)
AC_SUBST(ARCH_LIBS)
AC_SUBST(ARCH_DIR)
AC_SUBST(ARCH_SRC_DIR)
AC_SUBST(ARCH_MAKE_BINDIST_DIR)
AC_SUBST(ARCH_EXTRA_SUBDIR)
AC_SUBST(UI_LIBS)
AC_SUBST(SDL_EXTRA_LIBS)
AC_SUBST(SOUND_USS_OBJ)
AC_SUBST(SOUND_MIDAS_OBJ)
AC_SUBST(SOUND_SDL_OBJ)
AC_SUBST(WINDRES_LIB)

PLATFORM_DOX_FLAGS=""
if test x"$enable_platformdox" = "xyes"; then
  if test x"$enable_sdl1ui" = "xyes" -o x"$enable_sdl2ui" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformsdl"
  fi
  if test x"$enable_gtk3ui" = "xyes"; then
    PLATFORM_DOX_FLAGS="platformgtk3"
  fi
fi
if test x"$PLATFORM_DOX_FLAGS" = "x"; then
  PLATFORM_DOX_FLAGS="platformall"
fi
AC_SUBST(PLATFORM_DOX_FLAGS)

if test "$prefix" = NONE && test "$exec_prefix" = NONE; then
  PREFIX="$ac_default_prefix"
elif test "$prefix" = NONE; then
  PREFIX="$exec_prefix"
else
  PREFIX="$prefix"
fi

dnl Set up directories for the various OS'es
AC_DEFINE_UNQUOTED(PREFIX, "$PREFIX", [Where do we want to install the executable?])

dnl Exceptions for Windows and perhaps MacOS need to be made in the code since
dnl those are 'portable' (meaning any data is relative to the binary)

dnl VICEDIR="$datadir/$PACKAGE"
dnl VICE_ROOTDIR="$PREFIX"
dnl VICE_BINDIR="$bindir"
dnl VICE_DATADIR="$datadir/$PACKAGE"
dnl VICE_DOCDIR="$docdir"

dnl Set directories used by archdep
dnl
dnl Some of these are probably not required, we can either set some dirs to be
dnl relative, or use code to determine the location of files with bindists (ie
dnl Windows and MacOS)
dnl
dnl That will obviously require some target checks, the current stuff works
dnl targets that use `make install`, so at least Linux and BSD and perhaps
dnl MacOS when doing the 'Unix thing'.
dnl
dnl -- compyx, 2020-02-08
dnl
dnl AC_SUBST(VICEDIR, [$datadir/$PACKAGE])
dnl AC_SUBST(VICE_ROOTDIR, [$PREFIX])
dnl AC_SUBST(VICE_BINDIR, [$bindir])
AC_SUBST(VICE_DATADIR, [$datadir/$PACKAGE])
AC_SUBST(VICE_DOCDIR, [$docdir])


dnl Export --program-prefix and --program-suffix for the .desktop files
if test x"$program_prefix" = "xNONE"; then
    AC_SUBST(PROGRAM_PREFIX, "")
    #AC_MSG_ERROR([No prefix!])
else
    AC_SUBST(PROGRAM_PREFIX, [$program_prefix])
fi

if test x"$program_suffix" = "xNONE"; then
    AC_SUBST(PROGRAM_SUFFIX, "")
else
    AC_SUBST(PROGRAM_SUFFIX, [$program_suffix])
fi

AC_OUTPUT([Makefile
           build/Makefile
           build/beos/Makefile
           build/mingw/Makefile
           build/mingw/frankenvice/Makefile
           data/Makefile
           data/C128/Makefile
           data/C64/Makefile
           data/C64DTV/Makefile
           data/CBM-II/Makefile
           data/DRIVES/Makefile
           data/PET/Makefile
           data/PLUS4/Makefile
           data/SCPU64/Makefile
           data/PRINTER/Makefile
           data/VIC20/Makefile
           data/common/Makefile
           data/GLSL/Makefile
           doc/Makefile
           doc/building/Makefile
           doc/html/Makefile
           doc/readmes/Makefile
           doc/vim/Makefile
           doc/vim/ftdetect/Makefile
           doc/vim/syntax/Makefile
           src/Makefile
           src/debug.h
           src/arch/Makefile
           src/arch/gtk3/Makefile
           src/arch/gtk3/data/Makefile
           src/arch/gtk3/data/macos/Makefile
           src/arch/gtk3/data/unix/Makefile
           src/arch/gtk3/data/win32/Makefile
           src/arch/gtk3/joystickdrv/Makefile
           src/arch/gtk3/novte/Makefile
           src/arch/gtk3/widgets/Makefile
           src/arch/gtk3/widgets/base/Makefile
           src/arch/sdl/Makefile
           src/arch/headless/Makefile
           src/arch/shared/Makefile
           src/arch/shared/hwsiddrv/Makefile
           src/arch/shared/iodrv/Makefile
           src/arch/shared/mididrv/Makefile
           src/arch/shared/socketdrv/Makefile
           src/arch/shared/sounddrv/Makefile
           src/buildtools/Makefile
           src/c128/Makefile
           src/c128/cart/Makefile
           src/c64/Makefile
           src/c64/cart/Makefile
           src/c64dtv/Makefile
           src/scpu64/Makefile
           src/cbm2/Makefile
           src/cbm2/cart/Makefile
           src/core/Makefile
           src/core/rtc/Makefile
           src/crtc/Makefile
           src/datasette/Makefile
           src/diag/Makefile
           src/diskimage/Makefile
           src/drive/Makefile
           src/drive/iec/Makefile
           src/drive/iec/c64exp/Makefile
           src/drive/iec/plus4exp/Makefile
           src/drive/iec128dcr/Makefile
           src/drive/iecieee/Makefile
           src/drive/ieee/Makefile
           src/drive/tcbm/Makefile
           src/fileio/Makefile
           src/fsdevice/Makefile
           src/gfxoutputdrv/Makefile
           src/hvsc/Makefile
           src/iecbus/Makefile
           src/imagecontents/Makefile
           src/joyport/Makefile
           src/lib/Makefile
           src/lib/p64/Makefile
           src/monitor/Makefile
           src/parallel/Makefile
           src/pet/Makefile
           src/plus4/Makefile
           src/plus4/cart/Makefile
           src/printerdrv/Makefile
           src/raster/Makefile
           src/rs232drv/Makefile
           src/samplerdrv/Makefile
           src/serial/Makefile
           src/sid/Makefile
           src/tape/Makefile
           src/tapeport/Makefile
           src/tools/Makefile
           src/tools/cartconv/Makefile
           src/tools/petcat/Makefile
           src/userport/Makefile
           src/vdc/Makefile
           src/vdrive/Makefile
           src/vic20/Makefile
           src/vic20/cart/Makefile
           src/vicii/Makefile
           src/viciisc/Makefile
           src/video/Makefile
           src/version.h
           src/vice-version.sh
           ])

if test x"$enable_cmake" = x"yes" ; then
  "$srcdir/cmake-bootstrap.sh"
fi

dnl Local Variables:
dnl mode: autoconf
dnl compile-command: "autoconf"
dnl End:

dnl construct show_arch
if test "$is_beos" != "xyes" -a x"$is_unix_macosx" != "xyes" -a x"$is_win32" != "xyes" -a x"$is_win32_gtk3" != "xyes"; then
    show_arch="Unix"
    real_arch="Unix"
else
    if test x"$is_beos" = "xyes"; then
        show_arch="BeOS"
        real_arch="BeOS"
    fi
    if test x"$is_unix_macosx" = "xyes"; then
        show_arch="macOS $enable_macos_minimum_version"
        real_arch="OSX"
    fi
    if test x"$is_win32" = "xyes" -o x"$is_win32_gtk3" = "xyes"; then
        if test x"$enable_gtk3ui" = "xyes"; then
            show_arch="Win32-GTK3 (treated as Unix)"
            real_arch="Unix"
        fi
    fi
fi



dnl construct show_gui
show_gui="Unknown"
if test x"$enable_sdl1ui" = "xyes"; then
    show_gui="SDL 1.2"
fi

if test x"$enable_sdl2ui" = "xyes"; then
    show_gui="SDL 2.x"
fi

if test x"$enable_gtk3ui" = "xyes"; then
    if test x"$enable_debug_gtk3ui" = "xyes"; then
        show_gui="GTK3 (debug)"
    else
        show_gui="GTK3"
    fi
fi

if test x"$enable_headlessui" = "xyes"; then
    show_gui="Headless"
fi

if test "x$ac_cv_header_sys_audio_h" = xyes; then
    HAVE_SYS_AUDIO_H_SUPPORT="yes"
fi

if test "x$ac_cv_header_sys_audioio_h" = xyes; then
    HAVE_SYS_AUDIOIO_H_SUPPORT="yes"
fi

if test "x$ac_cv_func_SDL_NumJoysticks" = xyes; then
    HAVE_SDL_NUMJOYSTICKS_SUPPORT="yes"
fi


echo "----------------------------------------------------------------------"
echo ""
echo "configure summary:"
echo ""

echo "Platform canonical : $ac_cv_host"
echo "Architecture       : $show_arch"
echo "GUI                : $show_gui"
echo "Multithreaded UI   : $show_multithreaded"
echo "OpenMP             : $have_openmp"
if test x"$program_prefix" = "xNONE"; then
    echo "Program prefix     : (none) (--program-prefix)"
else
    echo "Program prefix     : $program_prefix (--program-prefix)"
fi
if test x"$program_suffix" = "xNONE"; then
    echo "Program suffix     : (none) (--program-suffix)"
else
    echo "Program suffix     : $program_suffix (--program-suffix)"
fi

echo ""
echo "SCREEN/UI"
echo "---------"
if test x"$real_arch" != "xBeOS"; then
    echo "Hardware scaling support       : $HAVE_HWSCALE_SUPPORT"
fi

echo ""
echo "SOUND"
echo "-----"
echo "FastSID support              : $HAVE_FASTSID_SUPPORT (--with/without-fastsid)"
echo "ReSID support                : $HAVE_RESID_SUPPORT (--with/without-resid)"
echo "New 8580 filter support      : $USE_NEW_8580_FILTER (--enable/disable-new8580filter)"
echo "PortAudio sound input support: $USE_PORTAUDIO_SUPPORT (--enable/disable-portaudio)"

if test x"$real_arch" = "xUnix"; then
    echo "OSS sound support            : $USE_OSS_SUPPORT (--with/without-oss)"
    echo "ALSA sound support           : $USE_ALSA_SUPPORT (--with/without-alsa)"
    echo "Pulseaudio sound support     : $USE_PULSE_SUPPORT (--with/without-pulse)"
fi

if test x"$real_arch" = "xOSX"; then
    echo "CoreAudio sound support      : $USE_COREAUDIO_SUPPORT"
    echo "AudioUnit sound support      : $HAVE_AUDIO_UNIT_SUPPORT"
fi

if test x"$real_arch" = "xWin32" -o x"$is_win32_gtk3" = "xyes"; then
    echo "DirectX sound support        : $USE_DXSOUND_SUPPORT"
fi

if test x"$real_arch" != "xDOS"; then
    echo "SDL sound support            : $USE_SDL_AUDIO_SUPPORT (--with/without-sdlsound)"
fi

if test x"$real_arch" = "xUnix"; then
    echo "NetBSD/Solaris sound support : $HAVE_SYS_AUDIOIO_H_SUPPORT"
fi

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xOSX" -o x"$real_arch" = "xWin32"; then
    echo "MIDI support                 : $HAVE_MIDI_SUPPORT (--enable/disable-midi)"
fi

if test x"$real_arch" != "xOSX" -a x"$real_arch" != "xBeOS"; then
    echo "Catweasel MK3 support        : $HAVE_CATWEASELMKIII_SUPPORT (--enable/disable-catweasel)"
    echo "HardSID support              : $HAVE_HARDSID_SUPPORT (--enable/disable-hardsid)"
fi

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xDOS" -o x"$real_arch" = "xWin32"; then
    echo "ParSID support               : $HAVE_PARSID_SUPPORT (--enable/disable-parsid)"
    echo "SSI2001 support              : $HAVE_SSI2001_SUPPORT (--enable/disable-ssi2001)"
    echo "direct I/O access support    : $HAVE_IOSID_SUPPORT"
    echo "lpt port access              : $HAVE_PORTSID_SUPPORT"
fi

echo "PCI utils support            : $HAVE_PCIUTILS_SUPPORT"

echo "MP3 encoding support         : $USE_LAMEMP3_SUPPORT (--enable/disable-lame)"
echo "MP3 decoding support         : $USE_MPG123_SUPPORT (--with/without-mpg123)"
echo "FLAC en/de-coding support    : $USE_FLAC_SUPPORT (--with/without-flac)"
echo "Vorbis en/de-coding support  : $USE_VORBIS_SUPPORT (--with/without-vorbis)"

echo ""
echo "SCREENSHOTS"
echo "-----------"

echo "GIF encoding support : $HAVE_GIF_SUPPORT (--with/without-gif)"
echo "PNG encoding support : $HAVE_PNG_SUPPORT (--with/without-png)"

echo ""
echo "VIDEO RECORDING"
echo "---------------"

echo "FFMPEG support                : $HAVE_FFMPEG_SUPPORT (--enable-ffmpeg)"
echo "FFMPEG swscale support        : $HAVE_FFMPEG_SWSCALE_SUPPORT"
if test x"$have_swresample" = "xyes"; then
  echo "Audio resampling library      : swresample"
elif test x"$have_avresample" = "xyes"; then
  echo "Audio resampling library      : avresample"
fi

echo ""
echo "INPUT"
echo "-----"

echo "Mouse support               : $HAVE_MOUSE_SUPPORT"
echo "Lightpen support            : $HAVE_LIGHTPEN_SUPPORT"


if test x"$real_arch" = "xUnix"; then
    if test x"$show_gui" != "xSDL" -a x"$show_gui" != "xSDL2"; then
        echo "Linux style joystick support: $LINUX_JOYSTICK_SUPPORT"
        echo "BSD style joystick support  : $BSD_JOYSTICK_SUPPORT"
        echo "USB joystick support        : $HAS_USB_JOYSTICK_SUPPORT"
    fi
fi

if test x"$real_arch" = "xOSX"; then
    if test x"$show_gui" != "xSDL" -a x"$show_gui" != "xSDL2"; then
        echo "Mac joystick support         : $MAC_JOYSTICK_SUPPORT"
        echo "IOHIDManager joystick support: $HAS_HIDMGR_SUPPORT (--enable/disable-hidmgr)"
    fi
fi

if test x"$real_arch" = "xWin32" -o x"$is_win32_gtk3" = "xyes"; then
    if test x"$show_gui" != "xSDL" -a x"$show_gui" != "xSDL2"; then
        echo "DirectInput joystick support: $HAVE_DINPUT_SUPPORT"
    fi
fi

if test x"$show_gui" = "xSDL" -o x"$show_gui" = "xSDL2"; then
    echo "SDL joystick support        : $HAVE_SDL_NUMJOYSTICKS_SUPPORT"
fi

echo ""
echo "MODEM/NETWORK"
echo "-------------"

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xWin32"; then
    echo "RS232 device support             : $HAVE_RS232DEV_SUPPORT (--enable/disable-rs232)"
fi

echo "Network support                  : $HAVE_NETWORK_SUPPORT"
echo "RS232 network support            : $HAVE_RS232NET_SUPPORT"
echo "IPv6 network support             : $HAVE_IPV6_SUPPORT (--enable/disable-ipv6)"
echo "Network capture/injection support: $HAVE_RAWNET_SUPPORT (--enable/disable-ethernet)"
echo "libcurl support                  : $HAVE_LIBCURL_SUPPORT (--with/without-libcurl)"

echo ""
echo "DRIVE"
echo "-----"

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xWin32"; then
  echo "Real device (OpenCBM support)    : $HAVE_REALDEVICE_SUPPORT (--enable/disable-realdevice)"
fi
echo "X64 image support                : $HAVE_X64_IMAGE_SUPPORT (--enable/disable--x64-image)"

dnl echo ""
dnl echo "MONITOR"
dnl echo "-------"
dnl echo "Native Gtk3 monitor support: $HAVE_GTK3_MONITOR_SUPPORT"

echo ""
echo "LIBS"
echo "----"

if test x"$real_arch" = "xUnix" -o x"$real_arch" = "xOSX" -o x"$real_arch" = "xWin32"; then
    echo "Dynamic linking support           : $HAVE_DYNLIB_SUPPORT_TOO"
fi

if test x"$real_arch" = "xUnix"; then
    echo "POSIX 1003.1e capabilities support: $HAVE_CAPABILITIES_SUPPORT"
fi

echo "zlib support                      : $HAVE_ZLIB_SUPPORT (--with/without-zlib)"

if test x"$real_arch" = "xUnix"; then
    echo "libieee1284 support               : $HAVE_LIBIEEE1284_SUPPORT"
fi


echo ""
echo "DOCUMENTATION"
echo "-------------"
echo -n "Generate Info/text: "
if test x"$MAKEINFO" = "x:"; then
    echo "no (install texinfo)"
else
    echo "yes"
fi
echo -n "Generate PDF      : "
if test x"$enable_pdf_docs" = xno; then
    echo "no (install texinfo)"
else
    echo "yes"
fi
echo -n "Generate HTML     : "
if test x"${enable_html_docs:-yes}" != xno; then
    echo "yes"
else
    echo "no"
fi

echo ""
echo "MISC"
echo "----"

echo "65xx CPU history support   : $FEATURE_CPUMEMHISTORY_SUPPORT (--enable/disable-cpuhistory)"
echo "Debug support              : $DEBUG_SUPPORT (--enable/disable-debug)"
echo "Threading debug support    : $DEBUG_THREADS_SUPPORT (--enable/disable-debug-threads"
echo "Build old x64 emulator     : $X64_INCLUDED (--enable/--disable-x64)"
echo "Install XDG .desktop files : $USE_DESKTOP_FILES"
echo "icotool for Windows found  : $ICOTOOL"

echo ""
echo "User CPPFLAGS:  $CPPFLAGS"
echo "VICE_CPPFLAGS:  $VICE_CPPFLAGS"
echo "User CFLAGS:    $CFLAGS"
echo "VICE CFLAGS:    $VICE_CFLAGS"
echo "User CXXFLAGS:  $CXXFLAGS"
echo "VICE CXXFLAGS:  $VICE_CXXFLAGS"
if test x"$is_unix_macosx" = "xyes"; then
  echo "User OBJCFLAGS: $OBJCFLAGS"
  echo "VICE OBJCFLAGS: $VICE_OBJCFLAGS"
fi
echo "VTE_CXXFLAGS:   $VTE_CXXFLAGS"
echo "MONITOR_CFLAGS: $MONITOR_CFLAGS"
echo "User LDFLAGS:   $LDFLAGS"
echo "VICE LDFLAGS:   $VICE_LDFLAGS"
echo "----------------------------------------------------------------------"

VICE_ARG_LIST_CHECK($cmdline_options, $enable_option_checking)