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

AC_INIT([swig],[4.1.0],[http://www.swig.org])
AC_PREREQ([2.60])

AC_CONFIG_SRCDIR([Source/Swig/swig.h])
AC_CONFIG_AUX_DIR([Tools/config])
AC_CONFIG_HEADERS([Source/Include/swigconfig.h])
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE

dnl Some extra defines for the config file
AH_BOTTOM([
/* Deal with attempt by Microsoft to deprecate C standard runtime functions */
#if defined(_MSC_VER)
# define _CRT_SECURE_NO_DEPRECATE
#endif
])

dnl Check for programs that a user requires to build SWIG
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O  # Needed for subdir-objects in AUTOMAKE_OPTIONS

AC_COMPILE_WARNINGS # Increase warning levels

AC_MSG_CHECKING([CFLAGS to compile SWIG executable])
AC_MSG_RESULT([$CFLAGS])
AC_MSG_CHECKING([CXXFLAGS to compile SWIG executable])
AC_MSG_RESULT([$CXXFLAGS])

AC_DEFINE_UNQUOTED(SWIG_CXX, ["$CXX"], [Compiler that built SWIG])
AC_DEFINE_UNQUOTED(SWIG_PLATFORM, ["$host"], [Platform that SWIG is built for])

# For AC_EGREP_CPP
AC_PROG_EGREP

dnl Look for popen
AC_ARG_WITH(popen, AS_HELP_STRING([--without-popen], [Disable popen]), with_popen="$withval")
if test x"${with_popen}" = xno ; then
AC_MSG_NOTICE([Disabling popen])
else
AC_CHECK_FUNC(popen, AC_DEFINE(HAVE_POPEN, 1, [Define if popen is available]), AC_MSG_NOTICE([Disabling popen]))
fi

dnl PCRE
AC_ARG_WITH([pcre],
  [AS_HELP_STRING([--without-pcre],
                  [Disable support for regular expressions using PCRE2])],
  [],
  [with_pcre=yes])

AC_MSG_CHECKING([whether to enable PCRE2 support])
AC_MSG_RESULT([$with_pcre])

dnl To make configuring easier, check for a locally built PCRE using the Tools/pcre-build.sh script
if test x"${with_pcre}" = xyes ; then
  AC_MSG_CHECKING([whether to use local PCRE2])
  local_pcre_config=no
  if test -z "$PCRE2_CONFIG"; then
    if test -f `pwd`/pcre/pcre-swig-install/bin/pcre2-config; then
      PCRE2_CONFIG=`pwd`/pcre/pcre-swig-install/bin/pcre2-config
      local_pcre_config=$PCRE2_CONFIG
    fi
  fi
  AC_MSG_RESULT([$local_pcre_config])
fi
AS_IF([test "x$with_pcre" != xno],
  [AX_PATH_GENERIC([pcre2],
    [], dnl Minimal version of PCRE we need -- accept any
    [], dnl custom sed script for version parsing is not needed
    [AC_DEFINE([HAVE_PCRE], [1], [Define if you have PCRE2 library])
     LIBS="$LIBS $PCRE2_LIBS"
     CPPFLAGS="$CPPFLAGS $PCRE2_CFLAGS"
    ],
    [AC_MSG_FAILURE([
        Cannot find pcre2-config script from PCRE2 (Perl Compatible Regular Expressions)
        library package. This dependency is needed for configure to complete,
        Either:
        - Install the PCRE2 developer package on your system (preferred approach).
        - Download the PCRE2 source tarball, build and install on your system
          as you would for any package built from source distribution.
        - Use the Tools/pcre-build.sh script to build PCRE2 just for SWIG to statically
          link against. Run 'Tools/pcre-build.sh --help' for instructions.
          (quite easy and does not require privileges to install PCRE2 on your system)
        - Use configure --without-pcre to disable regular expressions support in SWIG
          (not recommended).])
    ],
    [],[],[--libs8])
  ])


dnl CCache
AC_ARG_ENABLE([ccache], AS_HELP_STRING([--disable-ccache], [disable building and installation of ccache-swig executable (default enabled)]), [enable_ccache=$enableval], [enable_ccache=yes])
AC_MSG_CHECKING([whether to enable ccache-swig])
AC_MSG_RESULT([$enable_ccache])

if test "$enable_ccache" = yes; then
  AC_CONFIG_SUBDIRS(CCache)
  ENABLE_CCACHE=1
fi
AC_SUBST(ENABLE_CCACHE)


echo ""
echo "Checking packages required for SWIG developers."
echo "Note : None of the following packages are required for users to compile and install SWIG from the distributed tarball"
echo ""

AC_PROG_YACC

echo ""
echo "Checking for installed target languages and other information in order to compile and run"
echo "the examples and test-suite invoked by 'make check'."
echo "Note : None of the following packages are required for users to compile and install SWIG from the distributed tarball"
echo ""

dnl Some test cases require Boost
AX_BOOST_BASE(,,,)
AC_SUBST(BOOST_CPPFLAGS)

dnl Info for building shared libraries ... in order to run the examples

# SO is the extension of shared libraries (including the dot!)
AC_MSG_CHECKING(SO)
if test -z "$SO"
then
	case $host in
	*-*-hp*) SO=.sl;;
	*-*-darwin*) SO=.bundle;;
	*-*-cygwin* | *-*-mingw*) SO=.dll;;
	*) SO=.so;;
	esac
fi
AC_MSG_RESULT($SO)

# LDSHARED is the ld *command* used to create shared library
# -- "ld" on SunOS 4.x.x, "ld -G" on SunOS 5.x, "ld -shared" on IRIX 5
# (Shared libraries in this instance are shared modules to be loaded into
# Python, as opposed to building Python itself as a shared library.)
AC_MSG_CHECKING(LDSHARED)
if test -z "$LDSHARED"
then
	case $host in
	*-*-aix*) LDSHARED="$CC -shared";;
	*-*-cygwin* | *-*-mingw*)
            if test "$GCC" = yes; then
                LDSHARED="\$(CC) -shared"
            else
                if test "cl" = $CC ;  then
                    # Microsoft Visual C++ (MSVC)
                    LDSHARED="\$(CC) -nologo -LD"
                else
                    # Unknown compiler try gcc approach
                    LDSHARED="\$(CC) -shared"
                fi
            fi ;;
	*-*-irix5*) LDSHARED="ld -shared";;
	*-*-irix6*) LDSHARED="ld ${SGI_ABI} -shared -all";;
	*-*-sunos4*) LDSHARED="ld";;
	*-*-solaris*) LDSHARED="ld -G";;
	*-*-hp*) LDSHARED="ld -b";;
	*-*-osf*) LDSHARED="ld -shared -expect_unresolved \"*\"";;
	*-sequent-sysv4) LDSHARED="ld -G";;
	*-*-next*)
		if test "$ns_dyld"
		then LDSHARED="\$(CC) \$(LDFLAGS) -bundle -prebind"
		else LDSHARED="\$(CC) \$(CFLAGS) -nostdlib -r"
		fi
                if test "$with_next_framework" ; then
		    LDSHARED="$LDSHARED \$(LDLIBRARY)"
		fi ;;
	*-*-linux*) LDSHARED="\$(CC) -shared";;
	*-*-dgux*) LDSHARED="ld -G";;
	*-*-freebsd3*) LDSHARED="\$(CC) -shared";;
	*-*-freebsd* | *-*-openbsd*) LDSHARED="ld -Bshareable";;
	*-*-netbsd*)
		if [[ "`\$(CC) -dM -E - </dev/null | grep __ELF__`" != "" ]]
		then
			LDSHARED="\$(CC) -shared"
		else
			LDSHARED="ld -Bshareable"
		fi;;
	*-sco-sysv*) LDSHARED="\$(CC) -G -KPIC -Ki486 -belf -Wl,-Bexport";;
	*-*-darwin*) LDSHARED="\$(CC) -bundle -undefined suppress -flat_namespace";;
	*)	LDSHARED="ld";;
	esac
fi
AC_MSG_RESULT($LDSHARED)
# CXXSHARED is the ld *command* used to create C++ shared library
# -- "ld" on SunOS 4.x.x, "ld -G" on SunOS 5.x, "ld -shared" on IRIX 5
# (Shared libraries in this instance are shared modules to be loaded into
# Python, as opposed to building Python itself as a shared library.)
AC_MSG_CHECKING(CXXSHARED)
if test -z "$CXXSHARED"
then
	CXXSHARED="$LDSHARED"
fi
AC_MSG_RESULT($CXXSHARED)

#
AC_MSG_CHECKING(TRYLINKINGWITHCXX)
if test -z "$TRYLINKINGWITHCXX"
then
	case $host in
	*-*-solaris*) if test "$GCC" = yes
             then TRYLINKINGWITHCXX="CXXSHARED= \$(CXX) -Wl,-G"
             else TRYLINKINGWITHCXX="CXXSHARED= \$(CXX) -G -L/opt/SUNWspro/lib -lCrun -lCstd"
             fi;;
        *-*-hp*) TRYLINKINGWITHCXX="CXXSHARED= \$(CXX) +z ";;
        *-*-darwin*) TRYLINKINGWITHCXX="CXXSHARED= \$(CXX) -bundle -undefined suppress -flat_namespace";;
        *-*-cygwin* | *-*-mingw*)
            if test "$GCC" = yes; then
                TRYLINKINGWITHCXX="CXXSHARED= \$(CXX) -shared "
            else
                if test "cl" = $CXX ;  then
                    # Microsoft Visual C++ (MSVC)
                    TRYLINKINGWITHCXX="CXXSHARED= \$(CXX) -nologo -LD"
                else
                    TRYLINKINGWITHCXX="#unknown Windows compiler"
                fi
            fi ;;
        *)       TRYLINKINGWITHCXX="CXXSHARED= \$(CXX) -shared ";;
        esac
fi
AC_MSG_RESULT($TRYLINKINGWITHCXX)
# CCSHARED are the C *flags* used to create objects to go into a shared
# library (module) -- this is only needed for a few systems
AC_MSG_CHECKING(CCSHARED)
if test -z "$CCSHARED"
then
	case $host in
	*-*-hp*) if test "$GCC" = yes
		 then CCSHARED="-fpic"
		 else CCSHARED="+z"
		 fi;;
	s390x*-*-*) CCSHARED="-fpic" ;;
	s390*-*-*) CCSHARED="-fPIC" ;;
	*-*-linux*) CCSHARED="-fpic";;
	*-*-freebsd* | *-*-openbsd*) CCSHARED="-fpic";;
	*-*-netbsd*) CCSHARED="-fPIC";;
	*-sco-sysv*) CCSHARED="-KPIC -dy -Bdynamic";;
	*-*-irix6*)  case $CC in
		   *gcc*) CCSHARED="-shared";;
		   *) CCSHARED="";;
		   esac;;
	esac
fi
AC_MSG_RESULT($CCSHARED)

# RPATH is the path used to look for shared library files.
AC_MSG_CHECKING(RPATH)
if test -z "$RPATH"
then
	case $host in
	*-*-solaris*) RPATH='-R. -R$(exec_prefix)/lib';;
        *-*-irix*) RPATH='-rpath .:$(exec_prefix)/lib';;
	*-*-linux*) RPATH='-Xlinker -rpath $(exec_prefix)/lib -Xlinker -rpath .';;
	*)	RPATH='';;
	esac
fi
AC_MSG_RESULT($RPATH)

# LINKFORSHARED are the flags passed to the $(CC) command that links
# a few executables -- this is only needed for a few systems

AC_MSG_CHECKING(LINKFORSHARED)
if test -z "$LINKFORSHARED"
then
	case $host in
	*-*-aix*)	LINKFORSHARED='-Wl,-bE:$(srcdir)/python.exp -lld';;
	*-*-hp*)
	    LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";;
	*-*-linux*) LINKFORSHARED="-Xlinker -export-dynamic";;
	*-*-next*) LINKFORSHARED="-u libsys_s";;
	*-sco-sysv*) LINKFORSHARED="-Bdynamic -dy -Wl,-Bexport";;
	*-*-irix6*) LINKFORSHARED="-all";;
	esac
fi
AC_MSG_RESULT($LINKFORSHARED)

# Optional CFLAGS used to silence/enhance compiler warnings on some platforms.
AC_MSG_CHECKING(CFLAGS to use for testing (PLATCFLAGS))
case $host in
  *-*-solaris*) if test "$GCC" = yes
    then PLATCFLAGS=
    else PLATCFLAGS=
      #    else PLATCFLAGS="-errtags=yes" # Need more work as C examples use ld for linking
    fi;;
  *-*-aix*) PLATCFLAGS="$CFLAGS";;
  *) PLATCFLAGS=
esac
AC_MSG_RESULT($PLATCFLAGS)

# Add switch if necessary to enable C++11 support - just for tests
AC_ARG_ENABLE([cpp11-testing], AS_HELP_STRING([--disable-cpp11-testing], [disable C++11 and later C++ standards testing even if supported by compiler (default enabled)]), [enable_cpp11_testing=$enableval], [enable_cpp11_testing=yes])
AC_MSG_CHECKING([whether to attempt to enable C++11 and later C++ standards testing])
AC_MSG_RESULT([$enable_cpp11_testing])

PLATCXXFLAGS="$PLATCFLAGS"
if test x"$enable_cpp11_testing" = xyes; then
  CXX_SAVED=$CXX
  CXXCPP_SAVED=$CXXCPP

  # Test for c++17
  CXXCPP=" "
  AX_CXX_COMPILE_STDCXX(17, [noext], [optional])
  AC_MSG_CHECKING([whether C++11 to C++17 testing is enabled])
  if test "$HAVE_CXX17" = "1"; then
    AC_MSG_RESULT([yes])
    PLATCXXFLAGS="$CXXCPP $PLATCXXFLAGS"
    HAVE_CXX14="1"
    HAVE_CXX11="1"
  else
    AC_MSG_RESULT([no])

    # Test for c++14
    CXXCPP=" "
    CXX=$CXX_SAVED
    AX_CXX_COMPILE_STDCXX(14, [noext], [optional])
    AC_MSG_CHECKING([whether C++11 to C++14 testing is enabled])
    if test "$HAVE_CXX14" = "1"; then
      AC_MSG_RESULT([yes])
      PLATCXXFLAGS="$CXXCPP $PLATCXXFLAGS"
      HAVE_CXX11="1"
    else
      AC_MSG_RESULT([no])

      # Test for c++11
      CXXCPP=" "
      CXX=$CXX_SAVED
      AX_CXX_COMPILE_STDCXX(11, [noext], [optional])
      AC_MSG_CHECKING([whether C++11 testing is enabled])
      if test "$HAVE_CXX11" = "1"; then
        AC_MSG_RESULT([yes])
        PLATCXXFLAGS="$CXXCPP $PLATCXXFLAGS"
      else
        AC_MSG_RESULT([no])
      fi
    fi
  fi

  CXX=$CXX_SAVED
  CXXCPP=$CXXCPP_SAVED
fi
AC_SUBST(HAVE_CXX11)

# On darwin 10.7,10.8,10.9 using clang++, need to ensure using
# libc++ for tests and examples to run under mono. May affect
# other language targets as well - problem is a Mac OS X incompatibility
# between libraries depending on libstdc++ and libc++.
CLANGXX=
$CXX -v 2>&1 | grep -i clang >/dev/null && CLANGXX=yes
case $host in
  *-*-darwin11* | *-*-darwin12* |*-*-darwin13*  ) if test "$CLANGXX" = "yes";
    then PLATCXXFLAGS="$PLATCXXFLAGS -stdlib=libc++"
    fi;;
  *) ;;
esac

AC_MSG_CHECKING(CXXFLAGS to use for testing (PLATCXXFLAGS))
PLATCXXFLAGS=$(echo $PLATCXXFLAGS | xargs) # Trim whitespace
AC_MSG_RESULT([$PLATCXXFLAGS])

# Check for compiler pre-compiled header support
AC_MSG_CHECKING([if compiler supports pre-compiled headers])
PCHSUPPORT=no
if test "$CLANGXX" = "yes"; then
   PCHINCLUDEARG="-include-pch"
   PCHINCLUDEEXT=".gch"
else
   PCHINCLUDEARG="-include"
   PCHINCLUDEEXT=""
fi
AC_LANG_PUSH([C++])
echo '#include <cstdlib>' > conftest.hpp
echo '#include "conftest.hpp"' > conftest.cpp
$CXX -c conftest.hpp 2>/dev/null
if test $? -eq 0; then
   if test -f conftest.hpp.gch; then
      $CXX -H -c -I. ${PCHINCLUDEARG} ./conftest.hpp${PCHINCLUDEEXT} -o conftest.o conftest.cpp >conftest.out 2>&1
      if test $? -eq 0; then
         if test "$CLANGXX" = "yes"; then
            PCHSUPPORT=yes
         elif grep -q '^!.*conftest.hpp.gch$' conftest.out; then
            PCHSUPPORT=yes
         fi
      fi
   fi
fi
rm -f conftest.hpp conftest.cpp conftest.out
AC_LANG_POP([C++])
AC_MSG_RESULT([$PCHSUPPORT])
AC_SUBST(PCHSUPPORT)
AC_SUBST(PCHINCLUDEARG)
AC_SUBST(PCHINCLUDEEXT)

# Set info about shared libraries.
AC_SUBST(SO)
AC_SUBST(LDSHARED)
AC_SUBST(CCSHARED)
AC_SUBST(CXXSHARED)
AC_SUBST(TRYLINKINGWITHCXX)
AC_SUBST(RPATH)
AC_SUBST(PLATCFLAGS)
AC_SUBST(PLATCXXFLAGS)
AC_SUBST(LINKFORSHARED)

# This variation is needed on OS-X because there is no (apparent) consistency in shared library naming.
# Sometimes .bundle works, but sometimes .so is needed.  It depends on the target language

AC_SUBST(PYTHON_SO)
case $host in
   *-*-mingw*) PYTHON_SO=.pyd;;
   *-*-darwin*) PYTHON_SO=.so;;
   *) PYTHON_SO=$SO;;
esac

AC_SUBST(TCL_SO)
case $host in
   *-*-darwin*) TCL_SO=.dylib;;
   *) TCL_SO=$SO;;
esac

AC_SUBST(GUILE_SO)
case $host in
   *-*-darwin*) GUILE_SO=.so;;
   *) GUILE_SO=$SO;;
esac

AC_SUBST(PHP_SO)
case $host in
   *-*-darwin*) PHP_SO=.so;;
   *) PHP_SO=$SO;;
esac

AC_SUBST(MZSCHEME_SO)
case $host in
   *) MZSCHEME_SO=.so;;
esac

AC_SUBST(LUA_SO)
case $host in
   *-*-darwin*) LUA_SO=.so;;
   *) LUA_SO=$SO;;
esac

# Check for specific libraries.   Used for SWIG examples
AC_CHECK_LIB(dl, dlopen)	# Dynamic linking for SunOS/Solaris and SYSV
AC_CHECK_LIB(dld, shl_load)	# Dynamic linking for HP-UX

dnl The following three libraries (nsl,inet,socket) are needed on Sequent,
dnl and must be checked for in this order since each library depends on the
dnl preceding one.
dnl
dnl Most SVR4 platforms will need -lsocket and -lnsl.  However on SGI IRIX 5,
dnl these exist but are broken, so we use AC_SEARCH_LIBS which will only try
dnl the library if the function isn't already available without it.
AC_SEARCH_LIBS(t_open, nsl) # SVR4
AC_SEARCH_LIBS(gethostbyname, inet) # Sequent
AC_SEARCH_LIBS(socket, socket) # SVR4 sockets

# check for --with-libm=...
AC_SUBST(LIBM)
LIBM=-lm
AC_ARG_WITH(libm, [  --with-libm=STRING      math library], [
if test "$withval" != yes
then LIBM=$withval
else AC_MSG_ERROR([proper usage is --with-libm=STRING])
fi])
AC_CHECK_LIB(ieee, main, [LIBM="-lieee $LIBM"])
AC_CHECK_LIB(crypt,crypt, [LIBCRYPT="-lcrypt"])
AC_SUBST(LIBCRYPT)

# check for --with-libc=...
AC_SUBST(LIBC)
AC_ARG_WITH(libc, [  --with-libc=STRING      C library], [
if test "$withval" != yes
then LIBC=$withval
else AC_MSG_ERROR([proper usage is --with-libc=STRING])
fi])

#--------------------------------------------------------------------
# Target languages
#--------------------------------------------------------------------

AC_ARG_WITH(alllang, AS_HELP_STRING([--without-alllang], [Disable all languages]), with_alllang="$withval")

if test "$with_alllang" = "no"; then
  alllang_default=no
else
  alllang_default=yes
fi

AC_PATH_TOOL([PKG_CONFIG], [pkg-config])

#--------------------------------------------------------------------
# Look for Tcl
#--------------------------------------------------------------------

TCLINCLUDE=
TCLLIB=
TCLPACKAGE=
TCLLINK=

AC_ARG_WITH(tclconfig, AS_HELP_STRING([--without-tcl], [Disable Tcl])
AS_HELP_STRING([--with-tclconfig=path], [Set location of tclConfig.sh]), [with_tclconfig="$withval"], [with_tclconfig=])
AC_ARG_WITH(tcl,
 [  --with-tcl=path         Set location of Tcl package],[
	TCLPACKAGE="$withval"], [TCLPACKAGE="$alllang_default"])
AC_ARG_WITH(tclincl,[  --with-tclincl=path     Set location of Tcl include directory],[
	TCLINCLUDE="-I$withval"], [TCLINCLUDE=])
AC_ARG_WITH(tcllib,[  --with-tcllib=path      Set location of Tcl library directory],[
	TCLLIB="-L$withval"], [TCLLIB=])

# First, check for "--without-tcl" or "--with-tcl=no".
if test x"${TCLPACKAGE}" = xno; then
AC_MSG_NOTICE([Disabling Tcl])
else
AC_MSG_CHECKING([for Tcl configuration])
# First check to see if --with-tclconfig was specified.
if test x"${with_tclconfig}" != x ; then
   if test -f "${with_tclconfig}/tclConfig.sh" ; then
      TCLCONFIG=`(cd ${with_tclconfig}; pwd)`
   else
      AC_MSG_ERROR([${with_tcl} directory does not contain tclConfig.sh])
   fi
fi
# check in a few common install locations
dirs="/usr/lib*/ /usr/lib*/tcl*/ /usr/local/lib*/ /usr/local/lib*/tcl*/"
case $host in
*-*-darwin*)
  tcl_framework="/System/Library/Frameworks/Tcl.framework/"
  macos_sysroot="$(xcodebuild -version -sdk macosx Path 2>/dev/null)" # For MacOSX10.14 and later
  dirs="$macos_sysroot$tcl_framework $tcl_framework $dirs"
  ;;
*)
  ;;
esac
if test x"${TCLCONFIG}" = x ; then
  for d in $dirs ; do
    for i in `ls -d -r $d 2>/dev/null` ; do
      if test -f $i"tclConfig.sh" ; then
        TCLCONFIG=`(cd $i; pwd)`
        break
      fi
    done
  done
fi
if test x"${TCLCONFIG}" = x ; then
    AC_MSG_RESULT(no)
else
    AC_MSG_RESULT(found $TCLCONFIG/tclConfig.sh)
    . $TCLCONFIG/tclConfig.sh
    if test -z "$TCLINCLUDE"; then
        TCLINCLUDE=`echo $TCL_INCLUDE_SPEC`
    fi
    if test -z "$TCLLIB"; then
        TCLLIB=$TCL_LIB_SPEC
    fi
fi

if test -z "$TCLINCLUDE"; then
   if test "x$TCLPACKAGE" != xyes; then
	TCLINCLUDE="-I$TCLPACKAGE/include"
   fi
fi

if test -z "$TCLLIB"; then
   if test "x$TCLPACKAGE" != xyes; then
	TCLLIB="-L$TCLPACKAGE/lib -ltcl"
   fi
fi

AC_MSG_CHECKING(for Tcl header files)
if test -z "$TCLINCLUDE"; then
AC_PREPROC_IFELSE([AC_LANG_SOURCE([[#include <tcl.h>]])],[],[TCLINCLUDE=""])
if test -z "$TCLINCLUDE"; then
	dirs="/usr/local/include /usr/include /opt/local/include"
	for i in $dirs ; do
		if test -r $i/tcl.h; then
			AC_MSG_RESULT($i)
			TCLINCLUDE="-I$i"
			break
		fi
	done
fi
if test -z "$TCLINCLUDE"; then
    	AC_MSG_RESULT(not found)
fi
else
        AC_MSG_RESULT($TCLINCLUDE)
fi

AC_MSG_CHECKING(for Tcl library)
if test -z "$TCLLIB"; then
dirs="/usr/local/lib /usr/lib /opt/local/lib /opt/freeware/lib"
for i in $dirs ; do
	if test -r $i/libtcl.a; then
	    AC_MSG_RESULT($i)
	    TCLLIB="-L$i -ltcl"
	    break
	fi
done
if test -z "$TCLLIB"; then
	AC_MSG_RESULT(not found)
fi
else
AC_MSG_RESULT($TCLLIB)
fi

# Cygwin (Windows) needs the library for dynamic linking
case $host in
*-*-cygwin* | *-*-mingw*) TCLDYNAMICLINKING="$TCLLIB";;
*-*-aix*) TCLDYNAMICLINKING="$TCLLIB";;
*)TCLDYNAMICLINKING="";;
esac

# AIX needs -ltcl for linking at test time
case $host in
*-*-aix*) TCLLINK="-ltcl";;
*)TCLLINK="";;
esac

case $host in
*-*-darwin*)
    TCLLDSHARED='$(CC) -dynamiclib -undefined suppress -flat_namespace'
    TCLCXXSHARED='$(CXX) -dynamiclib -undefined suppress -flat_namespace'
    ;;
*)
    TCLLDSHARED='$(LDSHARED)'
    TCLCXXSHARED='$(CXXSHARED)'
    ;;
esac

fi

AC_SUBST(TCLINCLUDE)
AC_SUBST(TCLLIB)
AC_SUBST(TCLDYNAMICLINKING)
AC_SUBST(TCLLDSHARED)
AC_SUBST(TCLCXXSHARED)
AC_SUBST(TCLLINK)

#----------------------------------------------------------------
# Look for Python
#----------------------------------------------------------------

PYINCLUDE=
PYLIB=
PYLINK=
PYPACKAGE=

AC_ARG_WITH(python, AS_HELP_STRING([--without-python], [Don't probe for Python 2.x])
AS_HELP_STRING([--with-python=path], [Set location of Python 2.x executable]), [PYBIN="$withval"], [PYBIN="$alllang_default"])

# First, check for "--without-python" or "--with-python=no".
if test x"${PYBIN}" = xno; then
  AC_MSG_NOTICE([Disabling Python 2.x probe])
else
  # First figure out the name of the Python 2.x executable
  if test "x$PYBIN" = xyes; then
    AC_CHECK_PROGS(PYTHON, [python python2.7])
  else
    PYTHON="$PYBIN"
  fi

  PYVER=0
  if test -n "$PYTHON"; then
    AC_MSG_CHECKING([for $PYTHON major version number])
    PYVER=`($PYTHON -c "import sys; sys.stdout.write(sys.version[[0]])") 2>/dev/null`
    AC_MSG_RESULT($PYVER)
    if test -z "$PYVER"; then
      PYVER=0
    else
      AC_MSG_CHECKING(for Python 2.x os.name)
      PYOSNAME=`($PYTHON -c "import sys, os; sys.stdout.write(os.name)") 2>/dev/null`
      AC_MSG_RESULT($PYOSNAME)
      AC_MSG_CHECKING(for Python 2.x path separator)
      PYSEPARATOR=`($PYTHON -c "import sys, os; sys.stdout.write(os.sep)") 2>/dev/null`
      AC_MSG_RESULT($PYSEPARATOR)
    fi
  fi

  if test $PYVER -eq 1 -o $PYVER -eq 2; then
    AC_MSG_CHECKING(for Python 2.x prefix)
    PYPREFIX=`($PYTHON -c "import sys; sys.stdout.write(sys.prefix)") 2>/dev/null`
    AC_MSG_RESULT($PYPREFIX)
    AC_MSG_CHECKING(for Python 2.x exec-prefix)
    PYEPREFIX=`($PYTHON -c "import sys; sys.stdout.write(sys.exec_prefix)") 2>/dev/null`
    AC_MSG_RESULT($PYEPREFIX)

    if test x"$PYOSNAME" = x"nt" -a x"$PYSEPARATOR" = x"\\"; then
      # Windows installations are quite different to posix installations (MinGW path separator is a forward slash)
      PYPREFIX=`echo "$PYPREFIX" | sed -e 's,\\\\,/,g'` # Forward slashes are easier to use and even work on Windows most of the time
      PYTHON_SO=.pyd

      AC_MSG_CHECKING(for Python 2.x header files)
      if test -r $PYPREFIX/include/Python.h; then
        PYINCLUDE="-I$PYPREFIX/include"
      fi
      AC_MSG_RESULT($PYINCLUDE)

      AC_MSG_CHECKING(for Python 2.x library directory)
      if test -d $PYPREFIX/libs; then
        PYLIB=$PYPREFIX/libs
        PYLINKFILE=`ls $PYLIB/python*.lib | grep "python[[0-9]][[0-9]]\+\.lib"`
        if test -r "$PYLINKFILE"; then
          PYLINK=-l`basename $PYLINKFILE | sed -e 's/\.lib$//'`
        else
          PYLIB=
        fi
      fi
    else
      # Note: I could not think of a standard way to get the version string from different versions.
      # This trick pulls it out of the file location for a standard library file.

      AC_MSG_CHECKING(for Python 2.x version)

      # Need to do this hack since autoconf replaces __file__ with the name of the configure file
      filehack="file__"
      PYVERSION=`($PYTHON -c "import sys,string,operator,os.path; sys.stdout.write(operator.getitem(os.path.split(operator.getitem(os.path.split(string.__$filehack),0)),1))") 2>/dev/null`
      AC_MSG_RESULT($PYVERSION)

      # Find the directory for libraries this is necessary to deal with
      # platforms that can have apps built for multiple archs: e.g. x86_64
      AC_MSG_CHECKING(for Python 2.x lib dir)
      PYLIBDIR=`($PYTHON -c "import sys; sys.stdout.write(sys.lib)") 2>/dev/null`
      if test -z "$PYLIBDIR"; then
        # Fedora patch Python to add sys.lib, for other distros we assume "lib".
        PYLIBDIR="lib"
      fi
      AC_MSG_RESULT($PYLIBDIR)

      # Set the include directory

      AC_MSG_CHECKING(for Python 2.x header files)
      if test -r $PYPREFIX/include/$PYVERSION/Python.h; then
        PYINCLUDE="-I$PYPREFIX/include/$PYVERSION -I$PYEPREFIX/$PYLIBDIR/$PYVERSION/config"
      fi
      if test -z "$PYINCLUDE"; then
        if test -r $PYPREFIX/include/Py/Python.h; then
          PYINCLUDE="-I$PYPREFIX/include/Py -I$PYEPREFIX/$PYLIBDIR/python/lib"
        fi
      fi
      AC_MSG_RESULT($PYINCLUDE)

      # Set the library directory blindly.   This probably won't work with older versions
      AC_MSG_CHECKING(for Python 2.x library directory)
      dirs="$PYVERSION/config $PYVERSION/$PYLIBDIR python/$PYLIBDIR"
      for i in $dirs; do
        if test -d $PYEPREFIX/$PYLIBDIR/$i; then
          PYLIB="$PYEPREFIX/$PYLIBDIR/$i"
          break
        fi
      done

      PYLINK="-l$PYVERSION"
    fi

    if test -z "$PYLIB"; then
      AC_MSG_RESULT(Not found)
    else
      AC_MSG_RESULT($PYLIB)
    fi
    AC_MSG_CHECKING(for Python 2.x library)
    if test -z "$PYLINK"; then
      AC_MSG_RESULT(Not found)
    else
      AC_MSG_RESULT($PYLINK)
    fi
  fi

  # Cygwin (Windows) needs the library for dynamic linking
  case $host in
  *-*-cygwin* | *-*-mingw*)
    PYTHONDYNAMICLINKING="-L$PYLIB $PYLINK"
    DEFS="-DUSE_DL_IMPORT $DEFS"
    ;;
  *-*-aix*)
    PYTHONDYNAMICLINKING="-L$PYLIB $PYLINK"
    ;;
  *)PYTHONDYNAMICLINKING="";;
  esac
fi

AC_SUBST(PYINCLUDE)
AC_SUBST(PYLIB)
AC_SUBST(PYLINK)
AC_SUBST(PYTHONDYNAMICLINKING)


#----------------------------------------------------------------
# Look for Python 3.x
#----------------------------------------------------------------

PY3INCLUDE=
PY3LIB=
PY3LINK=
PY3PACKAGE=

AC_ARG_WITH(python3, AS_HELP_STRING([--without-python3], [Don't probe for Python 3.x])
AS_HELP_STRING([--with-python3=path], [Set location of Python 3.x executable]), [PY3BIN="$withval"], [PY3BIN="$alllang_default"])

# First, check for "--without-python3" or "--with-python3=no".
if test x"${PY3BIN}" = xno; then
  AC_MSG_NOTICE([Disabling Python 3.x probe])
else
  if test -z "$PYVER"; then
    PYVER=0
  fi
  if test "x$PY3BIN" = xyes; then
    if test x"$PYOSNAME" = x"nt" -a x"$PYSEPARATOR" = x"\\" -a $PYVER -ge 3; then
      PYTHON3="$PYTHON"
    else
      for py_ver in 3 3.10 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 ""; do
        AC_CHECK_PROGS(PYTHON3, [python$py_ver])
        if test -n "$PYTHON3"; then
          AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config])
          if test -n "$PY3CONFIG"; then
            break
          fi
        fi
      done
    fi
  else
    PYTHON3="$PY3BIN"
    AC_CHECK_PROGS(PY3CONFIG, [$PYTHON3-config])
  fi

  if test -n "$PYTHON3"; then
    AC_MSG_CHECKING([for $PYTHON3 major version number])
    PYVER=`($PYTHON3 -c "import sys; sys.stdout.write(sys.version[[0]])") 2>/dev/null`
    AC_MSG_RESULT($PYVER)
    if test -z "$PYVER"; then
      PYVER=0
    fi
  fi

  if test $PYVER -ge 3; then
    AC_MSG_CHECKING(for Python 3.x os.name)
    PY3OSNAME=`($PYTHON3 -c "import sys, os; sys.stdout.write(os.name)") 2>/dev/null`
    AC_MSG_RESULT($PY3OSNAME)
    AC_MSG_CHECKING(for Python 3.x path separator)
    PYSEPARATOR=`($PYTHON3 -c "import sys, os; sys.stdout.write(os.sep)") 2>/dev/null`
    AC_MSG_RESULT($PYSEPARATOR)

    if test x"$PY3OSNAME" = x"nt" -a x"$PYSEPARATOR" = x"\\"; then
      # Windows installations are quite different to posix installations
      # There is no python-config to use
      AC_MSG_CHECKING(for Python 3.x prefix)
      PY3PREFIX=`($PYTHON3 -c "import sys; sys.stdout.write(sys.prefix)") 2>/dev/null`
      AC_MSG_RESULT($PY3PREFIX)
      PY3PREFIX=`echo "$PY3PREFIX" | sed -e 's,\\\\,/,g'` # Forward slashes are easier to use and even work on Windows most of the time
      PYTHON_SO=.pyd

      AC_MSG_CHECKING(for Python 3.x header files)
      if test -r $PY3PREFIX/include/Python.h; then
        PY3INCLUDE="-I$PY3PREFIX/include"
      fi
      AC_MSG_RESULT($PY3INCLUDE)

      AC_MSG_CHECKING(for Python 3.x library directory)
      if test -d $PY3PREFIX/libs; then
        PY3LIB=$PY3PREFIX/libs
        PY3LINKFILE=`ls $PY3LIB/python*.lib | grep "python[[0-9]][[0-9]]\+\.lib"`
        if test -r "$PY3LINKFILE"; then
          PY3LINK=-l`basename $PY3LINKFILE | sed -e 's/\.lib$//'`
        else
          PY3LIB=
        fi
      fi
      if test -z "$PY3LIB"; then
        AC_MSG_RESULT([Not found])
      else
        AC_MSG_RESULT($PY3LIB)
      fi
      AC_MSG_CHECKING([for Python 3.x library])
      if test -z "$PY3LINK"; then
        AC_MSG_RESULT(Not found)
      else
        AC_MSG_RESULT($PY3LINK)
      fi
    elif test -n "$PY3CONFIG"; then
      AC_MSG_CHECKING([for Python 3.x prefix])
      PY3PREFIX=`($PY3CONFIG --prefix) 2>/dev/null`
      AC_MSG_RESULT($PY3PREFIX)
      AC_MSG_CHECKING(for Python 3.x exec-prefix)
      # Piped through xargs to strip trailing whitespace (bug in msys2 + mingw Python)
      PY3EPREFIX=`($PY3CONFIG --exec-prefix | xargs) 2>/dev/null`
      AC_MSG_RESULT($PY3EPREFIX)

      # Note: I could not think of a standard way to get the version string from different versions.
      # This trick pulls it out of the file location for a standard library file.

      AC_MSG_CHECKING([for Python 3.x version])

      # Need to do this hack since autoconf replaces __file__ with the name of the configure file
      filehack="file__"
      PY3VERSION=`($PYTHON3 -c "import string,operator,os.path; print(operator.getitem(os.path.split(operator.getitem(os.path.split(string.__$filehack),0)),1))") 2>/dev/null`
      AC_MSG_RESULT($PY3VERSION)

      # Find the directory for libraries this is necessary to deal with
      # platforms that can have apps built for multiple archs: e.g. x86_64
      AC_MSG_CHECKING([for Python 3.x lib dir])
      PY3LIBDIR=`($PYTHON3 -c "import sys; print(sys.lib)") 2>/dev/null`
      if test -z "$PY3LIBDIR"; then
        # some dists don't have sys.lib  so the best we can do is assume lib
        PY3LIBDIR="lib"
      fi
      AC_MSG_RESULT($PY3LIBDIR)

      # Set the include directory

      AC_MSG_CHECKING([for Python 3.x header files])
      PY3INCLUDE=`($PY3CONFIG --includes) 2>/dev/null`
      AC_MSG_RESULT($PY3INCLUDE)

      # Set the library directory blindly.   This probably won't work with older versions
      AC_MSG_CHECKING([for Python 3.x library directory])
      dirs="$PY3VERSION/config $PY3VERSION/$PY3LIBDIR python/$PY3LIBDIR"
      for i in $dirs; do
        if test -d $PY3EPREFIX/$PY3LIBDIR/$i; then
          PY3LIB="$PY3EPREFIX/$PY3LIBDIR/$i"
          break
        fi
      done
      if test -z "$PY3LIB"; then
        # Last resort
        if test -d $PY3EPREFIX/$PY3LIBDIR; then
          PY3LIB="$PY3EPREFIX/$PY3LIBDIR"
        fi
      fi
      if test -z "$PY3LIB"; then
        AC_MSG_RESULT([Not found])
      else
        AC_MSG_RESULT($PY3LIB)
      fi

      PY3LINK="-l$PY3VERSION"

      AC_MSG_CHECKING([for Python 3.x library])
      if test -z "$PY3LINK"; then
        AC_MSG_RESULT(Not found)
      else
        AC_MSG_RESULT($PY3LINK)
      fi
    fi
  fi

  # Cygwin (Windows) needs the library for dynamic linking
  case $host in
  *-*-cygwin* | *-*-mingw*)
    # PYTHON3DYNAMICLINKING ought to be replaced by $PY3CONFIG --ldflags
    PYTHON3DYNAMICLINKING="-L$PY3LIB $PY3LINK"
    DEFS="-DUSE_DL_IMPORT $DEFS"
    ;;
  *-*-aix*)
    PYTHON3DYNAMICLINKING="-L$PY3LIB $PY3LINK"
    ;;
  *)PYTHON3DYNAMICLINKING="";;
  esac

  AC_SUBST(PY3INCLUDE)
  AC_SUBST(PY3LIB)
  AC_SUBST(PY3LINK)
  AC_SUBST(PYTHON3DYNAMICLINKING)
fi

if test -n "$PYINCLUDE" || test -n "$PY3INCLUDE" ; then
  AC_CHECK_PROGS(PYCODESTYLE, pycodestyle)
  if test -n "$PYCODESTYLE"; then
    AC_MSG_CHECKING(pycodestyle version)
    pycodestyle_version=`$PYCODESTYLE --version 2>/dev/null`
    AC_MSG_RESULT($pycodestyle_version)
  fi
fi

#----------------------------------------------------------------
# Look for Perl5
#----------------------------------------------------------------

PERLBIN=

AC_ARG_WITH(perl5, AS_HELP_STRING([--without-perl5], [Disable Perl5])
AS_HELP_STRING([--with-perl5=path], [Set location of Perl5 executable]),[ PERLBIN="$withval"], [PERLBIN="$alllang_default"])

# First, check for "--without-perl5" or "--with-perl5=no".
if test x"${PERLBIN}" = xno; then
AC_MSG_NOTICE([Disabling Perl5])
PERL=
else

# First figure out what the name of Perl5 is

if test "x$PERLBIN" = xyes; then
AC_CHECK_PROGS(PERL, perl perl5)
else
PERL="$PERLBIN"
fi


# This could probably be simplified as for all platforms and all versions of Perl the following apparently should be run to get the compilation options:
# perl -MExtUtils::Embed -e ccopts
AC_MSG_CHECKING(for Perl5 header files)
if test -n "$PERL"; then
	PERL5DIR=`($PERL -MConfig -le 'print $Config{archlibexp}') 2>/dev/null`
	if test -n "$PERL5DIR" ; then
		dirs="$PERL5DIR $PERL5DIR/CORE"
		PERL5EXT=none
		for i in $dirs; do
			if test -r $i/perl.h; then
				AC_MSG_RESULT($i)
				PERL5EXT="$i"
				break
			fi
		done
		if test "$PERL5EXT" = none; then
			PERL5EXT="$PERL5DIR/CORE"
			AC_MSG_RESULT(could not locate perl.h...using $PERL5EXT)
		fi

		AC_MSG_CHECKING(for Perl5 library)
		PERL5LIB=`($PERL -e 'use Config; $_=$Config{libperl}; s/^lib//; s/$Config{_a}$//; s/\.$Config{so}.*//; print $_, "\n"') 2>/dev/null`
		if test -z "$PERL5LIB" ; then
			AC_MSG_RESULT(not found)
		else
			AC_MSG_RESULT($PERL5LIB)
		fi
    AC_MSG_CHECKING(for Perl5 ccflags)
 		PERL5CCFLAGS=`($PERL -e 'use Config; print $Config{ccflags}, "\n"' | sed "s/-Wdeclaration-after-statement//") 2>/dev/null`
 		if test -z "$PERL5CCFLAGS" ; then
 			AC_MSG_RESULT(not found)
 		else
 			AC_MSG_RESULT($PERL5CCFLAGS)
 		fi
    AC_MSG_CHECKING(for Perl5 ccdlflags)
    PERL5CCDLFLAGS=`($PERL -e 'use Config; print $Config{ccdlflags}, "\n"') 2>/dev/null`
    if test -z "$PERL5CCDLFLAGS" ; then
      AC_MSG_RESULT(not found)
      else
      AC_MSG_RESULT($PERL5CCDLFLAGS)
    fi
    AC_MSG_CHECKING(for Perl5 cccdlflags)
    PERL5CCCDLFLAGS=`($PERL -e 'use Config; print $Config{cccdlflags}, "\n"') 2>/dev/null`
    if test -z "$PERL5CCCDLFLAGS" ; then
      AC_MSG_RESULT(not found)
      else
      AC_MSG_RESULT($PERL5CCCDLFLAGS)
    fi
    AC_MSG_CHECKING(for Perl5 ldflags)
    PERL5LDFLAGS=`($PERL -e 'use Config; print $Config{ldflags}, "\n"') 2>/dev/null`
    if test -z "$PERL5LDFLAGS" ; then
      AC_MSG_RESULT(not found)
      else
      AC_MSG_RESULT($PERL5LDFLAGS)
    fi
    AC_MSG_CHECKING(for Perl5 Test::More module) # For test-suite
    PERL5TESTMORE=`($PERL -e 'use Test::More; print "good";') 2>/dev/null`
    if test -z "$PERL5TESTMORE" ; then
      AC_MSG_RESULT(not found)
      else
      AC_MSG_RESULT(found)
    fi
	else
		AC_MSG_RESULT(unable to determine perl5 configuration)
		PERL5EXT=$PERL5DIR
	fi
else
       	AC_MSG_RESULT(could not figure out how to run perl5)
fi

# Cygwin (Windows) needs the library for dynamic linking
case $host in
*-*-cygwin* | *-*-mingw*) PERL5DYNAMICLINKING="-L$PERL5EXT -l$PERL5LIB";;
*)PERL5DYNAMICLINKING="";;
esac
fi

AC_SUBST(PERL)
AC_SUBST(PERL5EXT)
AC_SUBST(PERL5DYNAMICLINKING)
AC_SUBST(PERL5LIB)
AC_SUBST(PERL5CCFLAGS)
AC_SUBST(PERL5CCDLFLAGS)
AC_SUBST(PERL5CCCDLFLAGS)
AC_SUBST(PERL5LDFLAGS)

#----------------------------------------------------------------
# Look for Octave
#----------------------------------------------------------------

OCTAVEBIN=
OCTAVE_SO=.oct

AC_ARG_WITH(octave, AS_HELP_STRING([--without-octave], [Disable Octave])
AS_HELP_STRING([--with-octave=path], [Set location of Octave executable]),[OCTAVEBIN="$withval"], [OCTAVEBIN="$alllang_default"])

# Check for "--without-octave" or "--with-octave=no".
if test x"${OCTAVEBIN}" = xno; then
   AC_MSG_NOTICE([Disabling Octave])
   OCTAVE=

# Check for Octave; prefer command-line program "octave-cli" to (in newer versions) GUI program "octave"
elif test "x$OCTAVEBIN" = xyes; then
   AC_PATH_PROG(OCTAVE, [octave-cli octave])

else
   OCTAVE="$OCTAVEBIN"
fi

# Check if Octave works
if test -n "$OCTAVE"; then
   AC_MSG_CHECKING([if ${OCTAVE} works])
   AS_IF([test "x`${OCTAVE} --version 2>/dev/null | sed -n -e '1p' | sed -n -e '/Octave, version/p'`" != x],[
      AC_MSG_RESULT([yes])
   ],[
      AC_MSG_RESULT([no])
      OCTAVE=
   ])
fi

# Check for required Octave helper program "mkoctfile"
if test -n "$OCTAVE"; then
  AC_MSG_CHECKING([for mkoctfile])
  version_suffix=["`echo $OCTAVE | sed -e 's|.*\(-[0-9][0-9.]*\)$|\1|'`"]
  case $version_suffix in
    -*) ;;
    *) version_suffix="" ;;
  esac
  octave_directory=`dirname $OCTAVE`
  if test "$octave_directory" = "." ; then
    mkoctfile="mkoctfile${version_suffix}"
  else
    mkoctfile="${octave_directory}/mkoctfile${version_suffix}"
  fi
  AC_MSG_RESULT([${mkoctfile}])
  AC_MSG_CHECKING([if ${mkoctfile} works])
  mkoctfile="env - PATH=$PATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH ${mkoctfile}"
  AS_IF([test "x`${mkoctfile} --version 2>/dev/null | sed -n -e '1p' | sed -n -e '/mkoctfile, version/p'`" != x],[
      AC_MSG_RESULT([yes])
    ],[
      AC_MSG_RESULT([no])
      OCTAVE=
    ])
fi

# Check for Octave preprocessor/compiler/linker flags
if test -n "$OCTAVE"; then

   AC_MSG_CHECKING([for Octave preprocessor flags])
   OCTAVE_CPPFLAGS=
   for var in CPPFLAGS INCFLAGS ALL_CXXFLAGS; do
      for flag in `${mkoctfile} -p ${var}`; do
         case ${flag} in
            -D*|-I*) OCTAVE_CPPFLAGS="${OCTAVE_CPPFLAGS} ${flag}";;
            *) ;;
         esac
      done
   done
   AC_MSG_RESULT([$OCTAVE_CPPFLAGS])

   AC_MSG_CHECKING([for Octave compiler flags])
   OCTAVE_CXXFLAGS=
   for var in CXX ALL_CXXFLAGS; do
      for flag in `${mkoctfile} -p ${var}`; do
         case ${flag} in
            -std=*|-g*|-W*) OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} ${flag}";;
            *) ;;
         esac
      done
   done
   save_CXXFLAGS="${CXXFLAGS}"
   CXXFLAGS="-Werror -O0"
   AC_COMPILE_IFELSE([
      AC_LANG_PROGRAM([],[])
   ],[
      OCTAVE_CXXFLAGS="${OCTAVE_CXXFLAGS} -O0"
   ])
   CXXFLAGS="${save_CXXFLAGS}"
   AC_MSG_RESULT([$OCTAVE_CXXFLAGS])

   AC_MSG_CHECKING([for Octave linker flags])
   OCTAVE_LDFLAGS=
   for var in OCTLIBDIR; do
     OCTAVE_LDFLAGS="${OCTAVE_LDFLAGS} "-L`${mkoctfile} -p ${var}`
   done
   for var in RDYNAMIC_FLAG RLD_FLAG OCTAVE_LIBS LIBS; do
     OCTAVE_LDFLAGS="${OCTAVE_LDFLAGS} "`${mkoctfile} -p ${var}`
   done
   AC_MSG_RESULT([$OCTAVE_LDFLAGS])

fi

# Check for Octave options
if test -n "$OCTAVE"; then
   for octave_opt in --no-window-system --silent --norc --no-history; do
      AC_MSG_CHECKING([if Octave option '${octave_opt}' is supported])
      octave_out=`${OCTAVE} ${octave_opt} /dev/null 2>&1 | sed -n '1p' | sed -n '/unrecognized/p'`
      AS_IF([test "x${octave_out}" = x],[
         AC_MSG_RESULT([yes])
         OCTAVE="${OCTAVE} ${octave_opt}"
      ],[
         AC_MSG_RESULT([no])
      ])
   done
fi

AC_SUBST(OCTAVE)
AC_SUBST(OCTAVE_SO)
AC_SUBST(OCTAVE_CPPFLAGS)
AC_SUBST(OCTAVE_CXXFLAGS)
AC_SUBST(OCTAVE_LDFLAGS)

#----------------------------------------------------------------
# Look for Scilab
#----------------------------------------------------------------

AC_ARG_WITH(scilab, AS_HELP_STRING([--without-scilab], [Disable Scilab])
AS_HELP_STRING([--with-scilab=path], [Set location of Scilab executable]),[SCILABBIN="$withval"], [SCILABBIN="$alllang_default"])
AC_ARG_WITH(scilab-inc, [  --with-scilab-inc=path  Set location of Scilab include directory], [SCILABINCDIR="$withval"], [SCILABINCDIR=""])

# First, check for "--without-scilab" or "--with-scilab=no".
if test x"${SCILABBIN}" = xno; then
  AC_MSG_NOTICE([Disabling Scilab])
  SCILAB=
else
  # Check for Scilab executable
  if test "x$SCILABBIN" = xyes; then
    AC_PATH_PROG(SCILAB, scilab)
  else
    AC_MSG_CHECKING(for scilab)
    if test -f "$SCILABBIN"; then
      AC_MSG_RESULT($SCILABBIN)
      SCILAB="$SCILABBIN"
    else
      AC_MSG_RESULT(not found)
    fi
  fi

  if test -n "$SCILAB"; then
    # Check for Scilab version (needs api_scilab so needs version 5.3.3 or higher)
    SCILAB_VERSION=`$SCILAB -nwni -version | head -1 | sed -e 's|Scilab version \"\(.*\)\"|\1|g'`

    AC_MSG_CHECKING(Scilab version is 5.3.3 or higher)
    SCILAB_MAJOR_VERSION=`echo $SCILAB_VERSION | cut -d. -f1`
    SCILAB_MINOR_VERSION=`echo $SCILAB_VERSION | cut -d. -f2`
    SCILAB_MAINTENANCE_VERSION=`echo $SCILAB_VERSION | cut -d. -f3`
    SCILAB_VERSION_NO_DOTS="$SCILAB_MAJOR_VERSION$SCILAB_MINOR_VERSION$SCILAB_MAINTENANCE_VERSION"

    if test -n "$SCILAB_VERSION_NO_DOTS" && test "$SCILAB_VERSION_NO_DOTS" -ge 533; then
      AC_MSG_RESULT(yes - $SCILAB_VERSION)
    else
      AC_MSG_RESULT(no - $SCILAB_VERSION)
      SCILAB=
    fi

    if test -n "$SCILAB"; then
      # Set Scilab startup options depending on version
      AC_MSG_CHECKING(for Scilab startup options)
      SCILABOPT="-nwni -nb"
      if test $SCILAB_VERSION_NO_DOTS -ge 540; then
        SCILABOPT+=" -noatomsautoload"
      fi
      if test $SCILAB_VERSION_NO_DOTS -ge 600; then
        SCILABOPT+=" -quit"
      fi
      AC_MSG_RESULT($SCILABOPT)

      # Check for Scilab header files
      AC_MSG_CHECKING(for Scilab header files)
      headers="`AS_DIRNAME(["$SCILAB"])`/../include"
      if test "$SCILABINCDIR" != ""; then
        dirs="$SCILABINCDIR"
      elif test -d "$SCI"; then
        dirs="$SCI/include $SCI/../../include"
      elif test -d "$headers"; then
        dirs="$headers"
      elif test -n "$PKG_CONFIG "; then
        dirs=`$PKG_CONFIG  scilab --cflags-only-I | sed -e 's/-I//g'`
      else
        dirs="/usr/include"
      fi
      for i in $dirs; do
        if test -r $i/api_scilab.h; then
          AC_MSG_RESULT($i)
          SCILABINCLUDE="-I$i"
          break
        fi
        if test -r $i/scilab/api_scilab.h; then
          AC_MSG_RESULT($i/scilab)
          SCILABINCLUDE="-I$i/scilab"
          break
        fi
      done
      if test "$SCILABINCLUDE" = "" ; then
        AC_MSG_RESULT(not found)
        SCILAB=
      fi
    fi
  fi
fi

AC_SUBST(SCILAB)
AC_SUBST(SCILABINCLUDE)
AC_SUBST(SCILABOPT)
AC_SUBST(SCILAB_VERSION)


#----------------------------------------------------------------
# Look for java
#----------------------------------------------------------------

AC_ARG_WITH(java, AS_HELP_STRING([--without-java], [Disable Java])
AS_HELP_STRING([--with-java=path], [Set location of java executable]),[JAVABIN="$withval"], [JAVABIN="$alllang_default"])
AC_ARG_WITH(javac, [  --with-javac=path       Set location of javac executable],[JAVACBIN="$withval"], [JAVACBIN=])

# First, check for "--without-java" or "--with-java=no".
if test x"${JAVABIN}" = xno; then
AC_MSG_NOTICE([Disabling Java])
JAVA=
else

dnl Detect everything we need for Java: java for running Java tests, javac for
dnl compiling them and C headers for compiling C code.
dnl
dnl If JAVA_HOME is defined and contains everything needed, as it's supposed to,
dnl just use it. Otherwise try to locate the necessary files in the path.
case $host in
  *-*-cygwin*)
    dnl Ensure that JAVA_HOME is in the form we can use, it's typically set to Windows path by the installer.
    if test -n "$JAVA_HOME"; then
      JAVA_HOME=`cygpath --mixed "$JAVA_HOME"`
    fi
    dnl Java uses semicolons and not colons as separators in its classes search path under Windows.
    JAVA_CLASSPATH_SEP=";"
    ;;
  *-*-mingw*)
    if test -n "$JAVA_HOME"; then
      JAVA_HOME=`${srcdir}/Tools/convertpath -u "$JAVA_HOME"`
    fi
    JAVA_CLASSPATH_SEP=";"
    ;;
  *-*-darwin*)
    dnl Under OS X JAVA_HOME is not set by default, try to use the system default JRE.
    if test -z "$JAVA_HOME" -a -x /usr/libexec/java_home; then
      JAVA_HOME=`/usr/libexec/java_home`
    fi
    dnl The JAVA_HOME doesn't contain the JDK headers though, but they seem to
    dnl always be in the same location, according to Apple JNI documentation.
    JAVA_OSX_STD_INCDIR="/System/Library/Frameworks/JavaVM.framework/Headers"
    if test -r "$JAVA_OSX_STD_INCDIR/jni.h"; then
      JAVA_HOME_INCDIR=$JAVA_OSX_STD_INCDIR
    fi
    JAVA_CLASSPATH_SEP=":"
    ;;
  *)
    dnl Assume generic Unix.
    JAVA_CLASSPATH_SEP=":"
    ;;
esac

AC_MSG_CHECKING(for java JDK)
if test -n "$JAVA_HOME"; then
  dnl Don't complain about missing executables/headers if they had been
  dnl explicitly overridden from the command line, but otherwise verify that we
  dnl have everything we need.
  java_home_ok=1
  if test -z "$JAVABIN" -a ! -x "$JAVA_HOME/bin/java"; then
    AC_MSG_WARN([No java executable under JAVA_HOME.])
    java_home_ok=0
  fi
  if test -z "$JAVACBIN" -a ! -x "$JAVA_HOME/bin/javac"; then
    AC_MSG_WARN([No javac executable under JAVA_HOME.])
    java_home_ok=0
  fi

  dnl By default the headers are under JAVA_HOME/include, but OS X is special
  dnl and defines JAVA_HOME_INCDIR differently above.
  if test -z "$JAVA_HOME_INCDIR"; then
    JAVA_HOME_INCDIR="$JAVA_HOME/include"
  fi
  if test -z "$JAVAINCDIR" -a ! -r "$JAVA_HOME_INCDIR/jni.h"; then
    AC_MSG_WARN([No java headers under JAVA_HOME (does it point to a JDK and not just JRE?).])
    java_home_ok=0
  fi
  if test "$java_home_ok" = 1; then
    AC_MSG_RESULT([found (in $JAVA_HOME)])
  else
    AC_MSG_RESULT(no)
    AC_MSG_WARN([JAVA_HOME ($JAVA_HOME) is defined but does not point to a complete JDK installation, ignoring it.])
    JAVA_HOME=
  fi
else
  AC_MSG_RESULT([no (JAVA_HOME is not defined)])
fi

if test "x$JAVABIN" = xyes; then
  if test -n "$JAVA_HOME"; then
    JAVA="$JAVA_HOME/bin/java"
  else
    AC_CHECK_PROGS(JAVA, java kaffe guavac)
  fi
else
  JAVA="$JAVABIN"
fi

if test -z "$JAVACBIN"; then
  if test -n "$JAVA_HOME"; then
    JAVAC="$JAVA_HOME/bin/javac"
  else
    AC_CHECK_PROGS(JAVAC, javac)
  fi
else
  JAVAC="$JAVACBIN"
fi

# Check Java version: we require Java 9 or later for Doxygen tests.
if test -n "$JAVAC"; then
    AC_MSG_CHECKING(if java version is 9 or greater)
    javac_version=`"$JAVAC" -version 2>&1`
    java_version_num=`echo $javac_version | sed -n 's/^javac //p'`
    if test -z "$java_version_num"; then
        AC_MSG_WARN([unknown format for Java version returned by "$JAVAC" ($javac_version)])
        JAVA_SKIP_DOXYGEN_TEST_CASES=1
        AC_MSG_RESULT(unknown)
    else
        dnl Until Java 8 version number was in format "1.x", starting from
        dnl Java 9 it's just "x".
        case $java_version_num in
            1.*)
                JAVA_SKIP_DOXYGEN_TEST_CASES=1
                AC_MSG_RESULT([no, disabling Doxygen tests])
                ;;

            *)
                AC_MSG_RESULT(yes)
                ;;
        esac
    fi

    AC_SUBST(JAVA_SKIP_DOXYGEN_TEST_CASES)
fi

AC_MSG_CHECKING(for java include file jni.h)
AC_ARG_WITH(javaincl, [  --with-javaincl=path    Set location of Java include directory], [JAVAINCDIR="$withval"], [JAVAINCDIR=])

JAVAINC=""
if test -z "$JAVAINCDIR" ; then
  if test -n "$JAVA_HOME"; then
    JAVAINCDIR="$JAVA_HOME_INCDIR"
    JAVAINC=-I\"$JAVAINCDIR\"
  else
    JAVAINCDIR="/usr/j2sdk*/include /usr/local/j2sdk*/include /usr/jdk*/include /usr/local/jdk*/include /opt/j2sdk*/include /opt/jdk*/include /usr/java/include /usr/java/j2sdk*/include /usr/java/jdk*/include /usr/local/java/include /opt/java/include /usr/include/java /usr/local/include/java /usr/lib/java/include /usr/lib/jvm/java*/include /usr/lib64/jvm/java*/include /usr/include/kaffe /usr/local/include/kaffe /usr/include"

    # Add in default installation directory on Windows for Cygwin
    case $host in
    *-*-cygwin* | *-*-mingw*) JAVAINCDIR="c:/Program*Files*/Java/jdk*/include d:/Program*Files*/Java/jdk*/include c:/j2sdk*/include d:/j2sdk*/include c:/jdk*/include d:/jdk*/include $JAVAINCDIR";;
    *-*-darwin*) JAVAINCDIR="$JAVA_OSX_STD_INCDIR $JAVAINCDIR";;
    *);;
    esac

    for d in $JAVAINCDIR ; do
      if test -r "$d/jni.h" ; then
	JAVAINCDIR=$d
	JAVAINC=-I\"$d\"
	JAVA_HOME_MAYBE="`dirname $d`"
	break
      fi
    done
  fi
else
  if test -r "$JAVAINCDIR/jni.h" ; then
    JAVAINC=-I\"$JAVAINCDIR\"
  fi
fi

if test "$JAVAINC" = "" ; then
  AC_MSG_RESULT(not found)
else
  AC_MSG_RESULT($JAVAINC)
  # now look for <arch>/jni_md.h
  AC_MSG_CHECKING(for java include file jni_md.h)
  JAVAMDDIR=`find "$JAVAINCDIR" -follow -name jni_md.h -print`
  if test "$JAVAMDDIR" = "" ; then
    AC_MSG_RESULT(not found)
  else
    JAVAMDDIR=-I\"`dirname "$JAVAMDDIR" | tail -1`\"
    AC_MSG_RESULT($JAVAMDDIR)
    JAVAINC="${JAVAINC} ${JAVAMDDIR}"
  fi
fi

# Auto-detecting JAVA_HOME is not so easy, below will only work up to and including jdk8
if test -z "$JAVA_HOME" && test -n "$JAVA_HOME_MAYBE" ; then
  AC_MSG_CHECKING(for java jdk from jni include paths)
  if test -r "$JAVA_HOME_MAYBE/lib/tools.jar" ; then
    JAVA_HOME=$JAVA_HOME_MAYBE
    AC_MSG_RESULT([$JAVA_HOME])
  else
    AC_MSG_RESULT(not found)
  fi
fi

case $host in
*-*-cygwin*)
        # TODO: Only use this flag if the compiler supports it, later versions of gcc no longer have it
        GCC_MNO_CYGWIN=" -mno-cygwin"
        ;;
*)
        GCC_MNO_CYGWIN=""
        ;;
esac

# java.exe on Cygwin requires the Windows standard (Pascal) calling convention as it is a normal Windows executable and not a Cygwin built executable
case $host in
*-*-cygwin* | *-*-mingw*)
    if test "$GCC" = yes; then
        JAVADYNAMICLINKING="$GCC_MNO_CYGWIN -mthreads -Wl,--add-stdcall-alias"
        JAVACFLAGS="$GCC_MNO_CYGWIN -mthreads"
    else
        JAVADYNAMICLINKING=""
        JAVACFLAGS=""
    fi ;;
*-*-darwin*)
        JAVADYNAMICLINKING="-dynamiclib -framework JavaVM"
        JAVACFLAGS=""
        ;;
*)
        JAVADYNAMICLINKING=""
        JAVACFLAGS=""
        ;;
esac

# Java on Windows platforms including Cygwin doesn't use libname.dll, rather name.dll when loading dlls
case $host in
*-*-cygwin* | *-*-mingw*) JAVALIBRARYPREFIX="";;
*)JAVALIBRARYPREFIX="lib";;
esac

# Java on Mac OS X tweaks
case $host in
*-*-darwin*)
    JAVASO=".jnilib"
    JAVALDSHARED='$(CC)'
    JAVACXXSHARED='$(CXX)'
    ;;
*)
    JAVASO=$SO
    JAVALDSHARED='$(LDSHARED)'
    JAVACXXSHARED='$(CXXSHARED)'
    ;;
esac
fi

# Quote for spaces in path to executables
if test -n "$JAVA"; then
  JAVA=\"$JAVA\"
fi
if test -n "$JAVAC"; then
  JAVAC=\"$JAVAC\"
fi

# Turned off due to spurious warnings in later versions of openjdk-1.8
# JAVAFLAGS=-Xcheck:jni

AC_SUBST(JAVA)
AC_SUBST(JAVAC)
AC_SUBST(JAVAINC)
AC_SUBST(JAVA_CLASSPATH_SEP)
AC_SUBST(JAVADYNAMICLINKING)
AC_SUBST(JAVALIBRARYPREFIX)
AC_SUBST(JAVASO)
AC_SUBST(JAVALDSHARED)
AC_SUBST(JAVACXXSHARED)
AC_SUBST(JAVAFLAGS)
AC_SUBST(JAVACFLAGS)

#----------------------------------------------------------------
# Look for Javascript
#----------------------------------------------------------------
AC_ARG_WITH(javascript, AS_HELP_STRING([--without-javascript], [Disable Javascript]), [with_javascript="$withval"], [with_javascript="$alllang_default"])

# First, check for "--without-javascript" or "--with-javascript=no".
if test x"${with_javascript}" = xno; then
  AC_MSG_NOTICE([Disabling Javascript])
  JAVASCRIPT=
else
  JAVASCRIPT=1

  #----------------------------------------------------------------
  # General Javascript settings shared by JSC and V8
  #----------------------------------------------------------------

  case $host in
  *-*-darwin*)
    JSSO=".dylib"
    # HACK: didn't manage to get dynamic module loading working with a g++ compiled interpreter
    JSINTERPRETERCXX='c++'
    JSINTERPRETERLINKFLAGS='-g -Wl,-search_paths_first -Wl,-headerpad_max_install_names'
    ;;
  *)
    JSSO=$SO
    JSINTERPRETERCXX='$(CXX)'
    JSINTERPRETERLINKFLAGS='-ldl'
    ;;
  esac

  #----------------------------------------------------------------
  # Look for Node.js which is the default Javascript engine
  #----------------------------------------------------------------

  AC_CHECK_PROGS(NODEJS, [node nodejs])

  if test -n "$NODEJS"; then
    # node-gyp is needed to run the test-suite/examples
    AC_CHECK_PROGS(NODEGYP, node-gyp)
    if test -z "$NODEGYP"; then
      NODEJS=
    fi
  fi

  #----------------------------------------------------------------
  # Look for JavascriptCore (Webkit) settings (JSCOREINCDIR, JSCOREDYNAMICLINKING)
  #----------------------------------------------------------------

  # check for include files
  AC_MSG_CHECKING(for JavaScriptCore/JavaScript.h)
  AC_ARG_WITH(jscoreinc, [  --with-jscoreinc=path      Set location of Javascript include directory], [JSCOREINCDIR="$withval"], [JSCOREINCDIR=])

  JSCOREVERSION=

  if test -z "$JSCOREINCDIR"; then
    JSCOREINCDIR="/usr/include/ /usr/local/include/"

    # Add in default directory for JavaScriptCore headers for Linux and Mac OS X
    case $host in
    *-*-linux*)
      JSCOREINCDIR="/usr/include/webkit-1.0/ /usr/include/webkitgtk-1.0/ /usr/local/include/webkit-1.0/JavaScriptCore/ $JSCOREINCDIR"
      ;;
    *-*-darwin*)
      JSCOREINCDIR="/System/Library/Frameworks/JavaScriptCore.framework/Headers/ $JSCOREINCDIR"
      ;;
    *)
      ;;
    esac
  fi

  for d in $JSCOREINCDIR ; do
    if test -r "$d/JavaScriptCore/JavaScript.h" || test -r "$d/JavaScript.h" ; then
      AC_MSG_RESULT($d)
      JSCOREINCDIR=$d
      JSCOREINC=-I\"$d\"
      break
    fi
  done

  if test "$JSCOREINC" = "" ; then
    AC_MSG_RESULT(not found)
  fi

  # check for JavaScriptCore/Webkit libraries
  AC_ARG_WITH(jscorelib,[  --with-jscorelib=path      Set location of the JavaScriptCore/Webkit library directory],[JSCORELIB="-L$withval"], [JSCORELIB=])

  if test -z "$JSCORELIB" -a -n "$PKG_CONFIG "; then
    AC_MSG_CHECKING(for JavaScriptCore/Webkit library)
    if $PKG_CONFIG  javascriptcoregtk-4.0 2>/dev/null ; then
      JSCORELIB=`$PKG_CONFIG  --libs javascriptcoregtk-4.0`
      JSCOREINC=`$PKG_CONFIG  --cflags-only-I javascriptcoregtk-4.0`
      JSCOREVERSION=`$PKG_CONFIG  --modversion javascriptcoregtk-4.0`
    elif $PKG_CONFIG  javascriptcoregtk-3.0 2>/dev/null ; then
      JSCORELIB=`$PKG_CONFIG  --libs javascriptcoregtk-3.0`
      JSCOREINC=`$PKG_CONFIG  --cflags-only-I javascriptcoregtk-3.0`
      JSCOREVERSION=`$PKG_CONFIG  --modversion javascriptcoregtk-3.0`
    elif $PKG_CONFIG  javascriptcoregtk-1.0 2>/dev/null ; then
      JSCORELIB=`$PKG_CONFIG  --libs javascriptcoregtk-1.0`
      JSCOREVERSION=`$PKG_CONFIG  --modversion javascriptcoregtk-1.0`
    fi
    if test -z "$JSCORELIB"; then
      AC_MSG_RESULT(not found)
      JSCENABLED=
    else
      AC_MSG_RESULT([$JSCORELIB])
      JSCOREDYNAMICLINKING="$JSCORELIB"
      JSCENABLED=1
    fi
  fi

  #----------------------------------------------------------------
  # Look for V8 settings (JSV8INCDIR, JSV8DYNAMICLINKING)
  #----------------------------------------------------------------

  # check for include files
  AC_MSG_CHECKING(for V8 Javascript v8.h)
  AC_ARG_WITH(jsv8inc, [  --with-jsv8inc=path     Set location of Javascript v8 include directory], [JSV8INCDIR="$withval"], [JSV8INCDIR=])

  # if not include dir is specified we try to find
  if test -z "$JSV8INCDIR"; then
    # Add in default directory for JavaScriptCore headers for Linux and Mac OS X
    case $host in
    *-*-linux*)
      JSV8INCDIR="/usr/include /usr/local/include/ $JSV8INCDIR"
      ;;
    *-*-darwin*)
      JSV8INCDIR="$JSV8INCDIR"
      ;;
    *)
      ;;
    esac
  fi

  for d in $JSV8INCDIR ; do
    if test -r "$d/v8.h" ; then
      JSV8INCDIR=$d
      JSV8INC=-I\"$d\"
      break
    fi
  done

  if test "$JSV8INC" = "" ; then
    AC_MSG_RESULT(not found)
  else
    AC_MSG_RESULT($JSV8INCDIR)
  fi

  # check for V8 library
  AC_MSG_CHECKING(for V8 Javascript library)
  AC_ARG_WITH(jsv8lib,[  --with-jsv8lib=path     Set location of V8 Javascript library directory],[JSV8LIBDIR="$withval"], [JSV8LIB=])

  v8libdirs="$JSV8LIBDIR /usr/lib64/ /usr/local/lib64/ /usr/lib/ /usr/local/lib/"
  for d in $v8libdirs ; do
    if test -r $d/libv8$JSSO; then
      JSV8LIBDIR=$d
      JSV8LIB="-L$d -lv8"
      break
    fi
  done

  if test "$JSV8LIB" = "" ; then
    AC_MSG_RESULT(not found)
    JSV8ENABLED=
  else
    AC_MSG_RESULT($JSV8LIBDIR)
    JSV8ENABLED=1
  fi


  # linking options
  case $host in
  *-*-darwin*)
    JSV8DYNAMICLINKING="$JSV8LIB"
    ;;
  *-*-linux*)
    JSV8DYNAMICLINKING="$JSV8LIB"
    ;;
  *)
    JSV8DYNAMICLINKING=""
    ;;
  esac

fi

AC_SUBST(JSINTERPRETERCXX)
AC_SUBST(JSINTERPRETERLINKFLAGS)

AC_SUBST(JSCOREINC)
AC_SUBST(JSCOREDYNAMICLINKING)
AC_SUBST(JSCOREVERSION)
AC_SUBST(JSV8INC)
AC_SUBST(JSV8DYNAMICLINKING)

AC_SUBST(JSCENABLED)
AC_SUBST(JSV8ENABLED)

AC_SUBST(NODEJS)
AC_SUBST(NODEGYP)

#----------------------------------------------------------------
# Look for Android
#----------------------------------------------------------------

AC_ARG_WITH(android, AS_HELP_STRING([--without-android], [Disable Android])
AS_HELP_STRING([--with-android=path], [Set location of android executable]),[ANDROIDBIN="$withval"], [ANDROIDBIN="$alllang_default"])
AC_ARG_WITH(adb, [  --with-adb=path         Set location of adb executable - Android Debug Bridge],[ADBBIN="$withval"], [ADBBIN=])
AC_ARG_WITH(ant, [  --with-ant=path         Set location of ant executable for Android],[ANTBIN="$withval"], [ANTBIN=])
AC_ARG_WITH(ndk-build, [  --with-ndk-build=path   Set location of Android ndk-build executable],[NDKBUILDBIN="$withval"], [NDKBUILDBIN=])

# First, check for "--without-android" or "--with-android=no".
if test x"${ANDROIDBIN}" = xno; then
  AC_MSG_NOTICE([Disabling Android])
  ANDROID=
else
  if test "x$ANDROIDBIN" = xyes; then
    AC_CHECK_PROGS(ANDROID, android)
  else
    ANDROID="$ANDROIDBIN"
  fi

  if test -z "$ADBBIN"; then
    AC_CHECK_PROGS(ADB, adb)
  else
    ADB="$ADBBIN"
  fi

  if test -z "$ANTBIN"; then
    AC_CHECK_PROGS(ANT, ant)
  else
    ANT="$ANTBIN"
  fi

  if test -z "$NDKBUILDBIN"; then
    AC_CHECK_PROGS(NDKBUILD, ndk-build)
  else
    NDKBUILD="$NDKBUILDBIN"
  fi
fi

AC_SUBST(ANDROID)
AC_SUBST(ADB)
AC_SUBST(ANT)
AC_SUBST(NDKBUILD)

#----------------------------------------------------------------
# Look for Guile
#----------------------------------------------------------------

GUILE=
GUILE_CFLAGS=
GUILE_LIBS=

AC_ARG_WITH(guile-config, AS_HELP_STRING([--without-guile], [Disable Guile])
AS_HELP_STRING([--with-guile-config=path], [Set location of guile-config]),[ GUILE_CONFIG="$withval"], [GUILE_CONFIG=])
AC_ARG_WITH(guile,[  --with-guile=path       Set location of Guile executable],[
	GUILE="$withval"], [GUILE="$alllang_default"])
AC_ARG_WITH(guile-cflags,[  --with-guile-cflags=cflags   Set cflags required to compile against Guile],[
	GUILE_CFLAGS="$withval"])
AC_ARG_WITH(guile-libs,[  --with-guile-libs=ldflags    Set ldflags needed to link with Guile],[
	GUILE_LIBS="$withval"])

# First, check for "--without-guile" or "--with-guile=no".
if test x"${GUILE}" = xno; then
  AC_MSG_NOTICE([Disabling Guile])
else
  if test -z "$GUILE_CONFIG" ; then
    AC_PATH_PROG(GUILE_CONFIG, guile-config)
  fi
  if test -n "$GUILE_CONFIG" ; then
    if test x"$GUILE" = xyes; then
      AC_MSG_CHECKING([for guile executable])
      # Try extracting it via guile-config first. If it's defined there it's the most reliable result
      GUILE="`$GUILE_CONFIG info guile 2>/dev/null`"
      if test -n "$GUILE";  then
        AC_MSG_RESULT([$GUILE])
      else
        AC_MSG_RESULT([not found via guile-config - constructing path])
        AC_MSG_CHECKING([for guile bindir])
        guile_bindir="`$GUILE_CONFIG info bindir`"
        AC_MSG_RESULT([$guile_bindir])
        GUILE="$guile_bindir/guile"
      fi
      if ! test -f "$GUILE" ; then
        GUILE=
        AC_PATH_PROG(GUILE, guile)
      fi
      if test -z "$GUILE" ; then
        AC_MSG_WARN([no suitable guile executable found. Disabling Guile])
      fi
    fi

    if test -n "$GUILE" ; then
      AC_MSG_CHECKING([for guile version])
      guile_version=`$GUILE -c '(display (effective-version))'`
      AC_MSG_RESULT([$guile_version])
      AC_MSG_CHECKING([for guile version >= 1.8])
      guile_good_version=`$GUILE -c '(if (>= (string->number (effective-version)) 1.8) (display "yes") (display "no"))'`
      AC_MSG_RESULT([$guile_good_version])
      if test x"$guile_good_version" != xyes ; then
        AC_MSG_WARN([at least guile version 1.8 is required. Disabling Guile])
        GUILE=
      fi
    fi

    if test -n "$GUILE" ; then
      # Test if guile-config and guile versions match. They should.
      gc_version="`$GUILE_CONFIG --version 2>&1 | sed '1 s/.* //;q'`"
      g_version="`$GUILE --version | sed '1 s/.* //;q'`"
      if test "$gc_version" != "$g_version"; then
        AC_MSG_WARN([different versions reported by $GUILE_CONFIG ($gc_version) and $GUILE ($g_version). Disabling Guile])
        GUILE=
      fi
    fi

    if test -n "$GUILE" ; then
      if test -z "$GUILE_CFLAGS" ; then
        AC_MSG_CHECKING([for guile compile flags])
        GUILE_CFLAGS="`$GUILE_CONFIG compile`" # Note that this can sometimes be empty
        AC_MSG_RESULT([$GUILE_CFLAGS])
      fi

      if test -z "$GUILE_LIBS" ; then
        AC_MSG_CHECKING([for guile link flags])
        GUILE_LIBS="`$GUILE_CONFIG link`"
        AC_MSG_RESULT([$GUILE_LIBS])
      fi
    fi
  fi
fi

AC_SUBST(GUILE)
AC_SUBST(GUILE_CFLAGS)
AC_SUBST(GUILE_LIBS)

#----------------------------------------------------------------
# Look for MzScheme
#----------------------------------------------------------------

AC_ARG_WITH(mzscheme, AS_HELP_STRING([--without-mzscheme], [Disable MzScheme])
AS_HELP_STRING([--with-mzscheme=path], [Set location of MzScheme executable]),[ MZSCHEMEBIN="$withval"], [MZSCHEMEBIN="$alllang_default"])
AC_ARG_WITH(mzc, AS_HELP_STRING([--with-mzc=path], [Set location of MzScheme's mzc]), [ MZCBIN="$withval"], [MZCBIN=])

# First, check for "--without-mzscheme" or "--with-mzscheme=no".
if test x"${MZSCHEMEBIN}" = xno; then
  AC_MSG_NOTICE([Disabling MzScheme])
  MZC=
else
  if test "x$MZSCHEMEBIN" = xyes; then
     AC_PATH_PROG(MZSCHEME, mzscheme)
  else
     MZSCHEME="$MZSCHEMEBIN"
  fi

  if test -z "$MZCBIN"; then
     AC_PATH_PROG(MZC, mzc)
  fi

  if test -n "$MZSCHEME"; then
    AC_MSG_CHECKING(for MzScheme dynext object)
    MZDYNOBJ=`$MZSCHEME --eval '(begin (require dynext/link) (with-handlers (((lambda args #t) (lambda args #f))) (for-each (lambda (x) (printf "~a" x)) (expand-for-link-variant (current-standard-link-libraries)))))' 2>/dev/null`
    if test -f "$MZDYNOBJ"; then
      :
    else
      # older versions (3.72 approx and earlier)
      MZDYNOBJ=`$MZSCHEME --mute-banner --version --eval '(begin (require (lib "link.ss" "dynext")) (with-handlers (((lambda args #t) (lambda args #f))) (for-each (lambda (x) (display x) (display " ")) ((current-make-standard-link-libraries)))) (with-handlers (((lambda args #t) (lambda args #f))) (for-each (lambda (x) (display x)) (expand-for-link-variant (current-standard-link-libraries)))))' 2>/dev/null`
    fi
    if test -f "$MZDYNOBJ"; then
      AC_MSG_RESULT($MZDYNOBJ)
    else
      AC_MSG_RESULT(not found)
      MZDYNOBJ=""
    fi
  fi
fi
AC_SUBST(MZDYNOBJ)

#----------------------------------------------------------------
# Look for Ruby
#----------------------------------------------------------------

RUBYBIN=

AC_ARG_WITH(ruby, AS_HELP_STRING([--without-ruby], [Disable Ruby])
AS_HELP_STRING([--with-ruby=path], [Set location of Ruby executable]),[ RUBYBIN="$withval"], [RUBYBIN="$alllang_default"])

# First, check for "--without-ruby" or "--with-ruby=no".
RUBYSO=$SO
if test x"${RUBYBIN}" = xno; then
AC_MSG_NOTICE([Disabling Ruby])
RUBY=
else

# First figure out what the name of Ruby is

if test "x$RUBYBIN" = xyes; then
	AC_CHECK_PROGS(RUBY, ruby)
else
	RUBY="$RUBYBIN"
fi

AC_MSG_CHECKING(for Ruby header files)
if test -n "$RUBY"; then
        # Try Ruby1.9+ first
        RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["rubyhdrdir"]] || $rubyhdrdir') 2>/dev/null`
        RUBYARCHHDRDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["rubyarchhdrdir"]] || $rubyarchhdrdir') 2>/dev/null`
	if test x"$RUBYDIR" = x"" || test x"$RUBYDIR" = x"nil"; then
		RUBYDIR=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["archdir"]] || $archdir') 2>/dev/null`
        else
                RUBYARCH=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["arch"]] || $arch') 2>/dev/null`
        fi
	if test x"$RUBYDIR" != x""; then
		dirs="$RUBYDIR"
		RUBYINCLUDE=
		for i in $dirs; do
			if test -r $i/ruby.h; then
				if test x"$RUBYARCH" = x""; then
					RUBYINCLUDE="-I$i"
				elif test -n "$RUBYARCHHDRDIR"; then
					RUBYINCLUDE="-I$i -I$RUBYARCHHDRDIR"
				else
					RUBYINCLUDE="-I$i -I$i/$RUBYARCH"
				fi
				AC_MSG_RESULT($RUBYINCLUDE)
				break
			fi
		done
		if test x"$RUBYINCLUDE" = x""; then
			AC_MSG_RESULT(could not locate ruby.h)
		fi

		# Find library and path for linking.
		AC_MSG_CHECKING(for Ruby library)
		RUBYLIB=""
		rb_archlibdir=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["archlibdir"]]') 2>/dev/null`
		rb_libdir=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["libdir"]]') 2>/dev/null`
		rb_bindir=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["bindir"]]') 2>/dev/null`
		dirs="$dirs $rb_archlibdir $rb_libdir $rb_bindir"

        rb_libruby=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["LIBRUBY_A"]]') 2>/dev/null`
        RUBYLINK=`($RUBY -rrbconfig -e '
            c = RbConfig::CONFIG
            if c.has_key? "LIBRUBYARG_STATIC" # 1.8.x
                if c[["LIBRUBY"]] == c[["LIBRUBY_A"]]
                    link = c[["LIBRUBYARG_STATIC"]]
                else
                    link = c[["LIBRUBYARG_SHARED"]]
                end
            else # 1.6.x
                link = "-l" + c[["RUBY_INSTALL_NAME"]]
            end

            # Get the target Ruby was built for
            target = c[["target"]]

            if target == "i386-pc-mswin32"
              # Need to change msvcrt-ruby*.lib to -lmsvcrt-ruby*
              ext = File.extname(link)
              # Get index that counts backwards from end of string
              index = -1 - ext.size
              # Strip off the extension
              link = link.slice(0..index)
              puts "-l#{link}"
            else
              puts link
            end') 2>/dev/null`

		if test "$rb_libruby" != ""; then
			for i in $dirs; do
				if (test -r $i/$rb_libruby;) then
					RUBYLIB="$i"
					break
				fi
			done
		fi
		if test "$RUBYLIB" = ""; then
			RUBYLIB="$RUBYDIR"
			AC_MSG_RESULT(not found... using $RUBYDIR)
		else
			AC_MSG_RESULT($RUBYLINK in $RUBYLIB)
		fi
	else
		AC_MSG_RESULT(unable to determine ruby configuration)
	fi

	case $host in
		*-*-mingw*) ;; # do nothing, the default windows libraries are already included
		*) RUBYLINK="$RUBYLINK `($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["LIBS"]]') 2>/dev/null`";;
	esac

	RUBYCCDLFLAGS=`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["CCDLFLAGS"]]') 2>/dev/null`
	RUBYSO=.`($RUBY -rrbconfig -e 'print RbConfig::CONFIG[["DLEXT"]]') 2>/dev/null`
else
	AC_MSG_RESULT(could not figure out how to run ruby)
fi

case $host in
*-*-cygwin* | *-*-mingw*)	RUBYDYNAMICLINKING="-L$RUBYLIB $RUBYLINK";;
*)		RUBYDYNAMICLINKING="";;
esac
fi

AC_SUBST(RUBYINCLUDE)
AC_SUBST(RUBYLIB)
AC_SUBST(RUBYLINK)
AC_SUBST(RUBYCCDLFLAGS)
AC_SUBST(RUBYSO)
AC_SUBST(RUBYDYNAMICLINKING)

#-------------------------------------------------------------------------
# Look for PHP
#-------------------------------------------------------------------------

PHPBIN=

AC_ARG_WITH(php, AS_HELP_STRING([--without-php], [Disable PHP])
AS_HELP_STRING([--with-php=path], [Set location of PHP executable]),[ PHPBIN="$withval"], [PHPBIN="$alllang_default"])

# First, check for "--without-php" or "--with-php=no".
if test x"${PHPBIN}" = xno; then
    AC_MSG_NOTICE([Disabling PHP])
    PHP=
else
    if test "x$PHPBIN" = xyes; then
      AC_CHECK_PROGS(PHP, [php8.1 php8.0 php7.4 php7.3 php7.2 php7.1 php7.0 php])
    else
      PHP=$PHPBIN
    fi

    if test -n "$PHP"; then
      AC_MSG_CHECKING(for PHP header files)
      dnl /usr/bin/php7.0 -> /usr/bin/php-config7.0
      case $PHP in
        *7.*)
          PHPCONFIG=`echo "$PHP"|sed 's/7\...*$/-config&/'` ;;
        *8.*)
          PHPCONFIG=`echo "$PHP"|sed 's/8\...*$/-config&/'` ;;
        *)
          PHPCONFIG=$PHP-config ;;
      esac
      php_version=`$PHPCONFIG --version 2>/dev/null`
      case $php_version in
      7.*|8.*)
        PHPINC=`$PHPCONFIG --includes 2>/dev/null`
        if test -n "$PHPINC"; then
          AC_MSG_RESULT($PHPINC)
        else
          AC_MSG_RESULT(not found)
        fi
        ;;
      "")
        AC_MSG_RESULT([could not find $PHPCONFIG or obtain PHP version from it]) ;;
      *)
        AC_MSG_RESULT([found PHP $php_version - not PHP 7 or 8]) ;;
      esac
    fi
fi
AC_SUBST(PHP)
AC_SUBST(PHPINC)

#----------------------------------------------------------------
# Look for OCaml
#----------------------------------------------------------------

AC_ARG_WITH(ocaml, AS_HELP_STRING([--without-ocaml], [Disable OCaml]), [with_ocaml="$withval"], [with_ocaml="$alllang_default"])
AC_ARG_WITH(ocamlc,[  --with-ocamlc=path      Set location of ocamlc executable],[ OCAMLC="$withval"], [OCAMLC=])
AC_ARG_WITH(ocamldlgen,[  --with-ocamldlgen=path  Set location of ocamldlgen],[ OCAMLDLGEN="$withval" ], [OCAMLDLGEN=])
AC_ARG_WITH(ocamlfind,[  --with-ocamlfind=path   Set location of ocamlfind],[OCAMLFIND="$withval"],[OCAMLFIND=])
AC_ARG_WITH(ocamlmktop,[  --with-ocamlmktop=path  Set location of ocamlmktop executable],[ OCAMLMKTOP="$withval"], [OCAMLMKTOP=])
AC_ARG_WITH(camlp4,[  --with-camlp4=path  Set location of camlp4 executable],[ CAMLP4="$withval"], [CAMLP4=])

# First, check for "--without-ocaml" or "--with-ocaml=no".
if test x"${with_ocaml}" = xno; then
    AC_MSG_NOTICE([Disabling OCaml])
    OCAMLC=
else
    # OCaml compiler
    if test -z "$OCAMLC"; then
	AC_CHECK_PROGS(OCAMLC, ocamlc)
    fi

    # OCaml Pre-Processor-Pretty-Printer
    if test -z "$CAMLP4"; then
	AC_CHECK_PROGS(CAMLP4, camlp4)
    fi

    # OCaml DL load generator
    if test -z "$OCAMLDLGEN"; then
	AC_CHECK_PROGS(OCAMLDLGEN, ocamldlgen)
    fi

    # OCaml package tool
    if test -z "$OCAMLFIND"; then
	AC_CHECK_PROGS(OCAMLFIND, ocamlfind)
    fi

    # OCaml toplevel creator
    if test -z "$OCAMLMKTOP"; then
	AC_CHECK_PROGS(OCAMLMKTOP, ocamlmktop)
    fi
fi

AC_SUBST(OCAMLC)
AC_SUBST(CAMLP4)
AC_SUBST(OCAMLDLGEN)
AC_SUBST(OCAMLFIND)
AC_SUBST(OCAMLMKTOP)

#----------------------------------------------------------------
# Look for C#
#----------------------------------------------------------------

AC_ARG_WITH(csharp, AS_HELP_STRING([--without-csharp], [Disable CSharp]), [with_csharp="$withval"], [with_csharp="$alllang_default"])
AC_ARG_WITH(cil-interpreter, [  --with-cil-interpreter=path     Set location of CIL interpreter for CSharp],[CSHARPBIN="$withval"], [CSHARPBIN=])
AC_ARG_WITH(csharp-compiler, [  --with-csharp-compiler=path     Set location of CSharp compiler],[CSHARPCOMPILERBIN="$withval"], [CSHARPCOMPILERBIN=])

# First, check for "--without-csharp" or "--with-csharp=no".
if test x"${with_csharp}" = xno; then
AC_MSG_NOTICE([Disabling CSharp])
CSHARPCOMPILER=
else

if test -z "$CSHARPCOMPILERBIN" ; then
  case $host in
  *-*-cygwin* | *-*-mingw*)
    # prefer unified Mono mcs compiler (not to be confused with the ancient .NET 1 mcs) over older/alternative names.
    AC_CHECK_PROGS(CSHARPCOMPILER, csc mcs mono-csc gmcs cscc)
    if test -n "$CSHARPCOMPILER" && test "$CSHARPCOMPILER" = "csc" ; then
      AC_MSG_CHECKING(whether csc is the Microsoft CSharp compiler)
      csc 2>/dev/null | grep "C#" > /dev/null || CSHARPCOMPILER=""
      if test -z "$CSHARPCOMPILER" ; then
        AC_MSG_RESULT(no)
        AC_CHECK_PROGS(CSHARPCOMPILER, mcs mono-csc gmcs cscc)
      else
        AC_MSG_RESULT(yes)
      fi
    fi
    ;;
  *)AC_CHECK_PROGS(CSHARPCOMPILER, mono-csc gmcs mcs cscc);;
  esac
else
  CSHARPCOMPILER="$CSHARPCOMPILERBIN"
fi

CSHARPCONVERTPATH="Tools/convertpath -u"
if test -z "$CSHARPBIN" ; then
  CSHARPCILINTERPRETER=""
  CSHARPCILINTERPRETER_FLAGS=""
  if test "cscc" = "$CSHARPCOMPILER" ; then
    AC_CHECK_PROGS(CSHARPCILINTERPRETER, ilrun)
  else
    if test "mcs" = "$CSHARPCOMPILER"; then
      # Check that mcs is the C# compiler and not the Unix mcs utility by examining the output of 'mcs --version'
      # The Mono compiler should emit: Mono C# compiler version a.b.c.d
      csharp_version_raw=`(mcs --version) 2>/dev/null`
      csharp_version_searched=`(mcs --version | sed -e "/C#/b" -e "/Mono/b" -e d) 2>/dev/null` # return string if contains 'Mono' or 'C#'
      CSHARPCOMPILER=""
      if test -n "$csharp_version_raw" ; then
        if test "$csharp_version_raw" = "$csharp_version_searched" ; then
          CSHARPCOMPILER="mcs"
        fi
      fi
      if test "mcs" != "$CSHARPCOMPILER" ; then
        echo "mcs is not a working Mono C# compiler"
      fi
    fi
    if test "mcs" = "$CSHARPCOMPILER" || test "gmcs" = "$CSHARPCOMPILER" || test "mono-csc" = "$CSHARPCOMPILER"; then
        AC_CHECK_PROGS(CSHARPCILINTERPRETER, mono) # Mono JIT
        CSHARPCILINTERPRETER_FLAGS="--debug"
    else
      if test "csc" = "$CSHARPCOMPILER"; then
          CSHARPCONVERTPATH="Tools/convertpath -w"
      fi
    fi
  fi
else
  CSHARPCILINTERPRETER="$CSHARPBIN"
fi

# Cygwin requires the Windows standard (Pascal) calling convention as it is a Windows executable and not a Cygwin built executable
case $host in
*-*-cygwin* | *-*-mingw*)
    if test "$GCC" = yes; then
        CSHARPDYNAMICLINKING="$GCC_MNO_CYGWIN -mthreads -Wl,--add-stdcall-alias"
        CSHARPCFLAGS="$GCC_MNO_CYGWIN -mthreads"
    else
        CSHARPDYNAMICLINKING=""
        CSHARPCFLAGS=""
    fi ;;
*)
        CSHARPDYNAMICLINKING=""
        CSHARPCFLAGS=""
        ;;
esac

# CSharp on Windows platforms including Cygwin doesn't use libname.dll, rather name.dll when loading dlls
case $host in
*-*-cygwin* | *-*-mingw*) CSHARPLIBRARYPREFIX="";;
*)CSHARPLIBRARYPREFIX="lib";;
esac

# C#/Mono on Mac OS X tweaks
case $host in
*-*-darwin*)
    CSHARPSO=".so"
    ;;
*)
    CSHARPSO=$SO
    ;;
esac
fi

AC_SUBST(CSHARPCILINTERPRETER_FLAGS)
AC_SUBST(CSHARPCILINTERPRETER)
AC_SUBST(CSHARPCONVERTPATH)
AC_SUBST(CSHARPCOMPILER)
AC_SUBST(CSHARPDYNAMICLINKING)
AC_SUBST(CSHARPLIBRARYPREFIX)
AC_SUBST(CSHARPCFLAGS)
AC_SUBST(CSHARPSO)

#----------------------------------------------------------------
# Look for Lua
#----------------------------------------------------------------

LUABIN=
LUAINCLUDE=
LUALIB=
LUADYNAMICLOADLIB=
LUAFLAGS=
LUALINK=
# note: if LUABIN is empty then lua tests will not be done
# LUABIN will be cleared if certain dependencies cannot be found

AC_ARG_WITH(lua, AS_HELP_STRING([--without-lua], [Disable Lua])
AS_HELP_STRING([--with-lua=path], [Set location of Lua executable]),[ LUABIN="$withval"], [LUABIN="$alllang_default"])
AC_ARG_WITH(luaincl,[  --with-luaincl=path     Set location of Lua include directory],[
	LUAINCLUDE="$withval"], [LUAINCLUDE=])
AC_ARG_WITH(lualib,[  --with-lualib=path      Set location of Lua library directory],[
	LUALIB="$withval"], [LUALIB=])

# First, check for "--without-lua" or "--with-lua=no".
if test x"${LUABIN}" = xno; then
AC_MSG_NOTICE([Disabling Lua])
else

# can we find lua?
if test "x$LUABIN" = xyes; then
   # We look for a versioned Lua binary first, as there can be
   # multiple versions of Lua installed on some systems (like Debian).
   AC_PATH_PROGS(LUABIN, [lua5.4 lua5.3 lua5.2 lua5.1 lua])
fi

# check version: we need Lua 5.x
if test "$LUABIN"; then
  AC_MSG_CHECKING(Lua version)
  [LUA_VERSION=`$LUABIN -e 'print(string.match(_VERSION, "%d+[.]%d+"))'`]
  # For 5.0 and 5.1 header and libraries may be named using 50 or 51.
  LUA_VERSION_NO_DOTS=
  if test -n "$LUA_VERSION" ; then
    AC_MSG_RESULT([Lua $LUA_VERSION.x])
  else
    AC_MSG_RESULT([failed])
  fi
  case $LUA_VERSION in
    5.0) LUA_VERSION_NO_DOTS=50 ;;
    5.1) LUA_VERSION_NO_DOTS=51 ;;
    5.*) ;;
    *)
      AC_MSG_WARN([Not Lua 5.x, SWIG does not support this version of Lua])
      LUABIN=""
      ;;
  esac
fi

if test "$LUABIN"; then
  AC_MSG_CHECKING(whether Lua dynamic loading is enabled)
  # using Lua to check Lua
  # lua 5.0 & 5.1 have different fn names
  if test "$LUA_VERSION" = "5.0"; then
    LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=loadlib("no_such_lib","") if c~="absent" then print "1" end'`
  else
    LUADYNAMICLOADLIB=`$LUABIN -e '_,_,c=package.loadlib("no_such_lib","") if c~="absent" then print "1" end'`
  fi

  if test -z "$LUADYNAMICLOADLIB"; then
    AC_MSG_RESULT(no)
  else
    AC_MSG_RESULT(yes)
  fi

  # look for the header files & set LUAFLAGS accordingly
  # will clear LUABIN if not present
  if test -n "$LUAINCLUDE"; then
    AC_CHECK_FILE($LUAINCLUDE/lua.h,[LUAFLAGS="-I$LUAINCLUDE"],[LUABIN=])
  else
    LUA_OK="1"
    CFLAGS_SAVED=$CFLAGS
    CFLAGS= # Use empty CFLAGS to avoid failure: "present but cannot be compiled"
    AC_CHECK_HEADER([lua.h],[LUAFLAGS=""],[LUA_OK=""])
    CFLAGS=$CFLAGS_SAVED
    # if we didn't get it, going to have to look elsewhere (the hard way)
    if test -z "$LUA_OK"; then
      AC_MSG_CHECKING(for lua.h in other locations)
      # note: Debian/Ubuntu seem to like /usr/include/lua5.1/lua.h
      # The ordering of the include directories to search should match
      # the ordering of libraries to search in the library test below.
      inc=/usr/include
      incloc=/usr/local/include
      dirs="$inc/lua$LUA_VERSION"
      test -z "$LUA_VERSION_NO_DOTS" || dirs="$dirs $inc/lua$LUA_VERSION_NO_DOTS"
      dirs="$dirs $incloc/lua$LUA_VERSION"
      test -z "$LUA_VERSION_NO_DOTS" || dirs="$dirs $incloc/lua$LUA_VERSION_NO_DOTS"
      dirs="$dirs $incloc"
      for i in $dirs; do
        #echo "$i"
        if test -r $i/lua.h; then
          AC_MSG_RESULT($i/lua.h)
          LUAFLAGS="-I$i"
          break
        fi
      done
      if test -z "$LUAFLAGS"; then
        AC_MSG_RESULT(not found)
        LUABIN="" # clear the bin
      fi
    fi
  fi

  # look for the library files & set LUALINK accordingly
  # will clear LUABIN if not present
  lua_save_LIBS=$LIBS # the code seems to disrupt LIBS, so saving

  if test -n "$LUALIB"; then
    AC_CHECK_FILE($LUALIB/liblua.a,[LUALINK="-L$LUALIB -llua"],[LUABIN=])
  else
    libs="lua lua$LUA_VERSION"
    test -z "$LUA_VERSION_NO_DOTS" || libs="$libs lua$LUA_VERSION_NO_DOTS"
    AC_SEARCH_LIBS(lua_close, [$libs], [LUALINK="-l$ac_lib"],[LUABIN=])
  fi

  # adding lualib for lua 5.0
  if test "$LUA_VERSION" = "5.0"; then
    LUALINK="$LUALINK -llualib"
  fi

  LIBS=$lua_save_LIBS	# restore LIBS
fi

fi # if not disabled

AC_SUBST(LUADYNAMICLINKING)
AC_SUBST(LUAFLAGS)
AC_SUBST(LUALINK)
AC_SUBST(LUABIN)

#----------------------------------------------------------------
# Look for GNU R
#----------------------------------------------------------------

RBIN=

AC_ARG_WITH(r, AS_HELP_STRING([--without-r], [Disable R])
AS_HELP_STRING([--with-r=path], [Set location of R executable (r)]),[ RBIN="$withval"], [RBIN="$alllang_default"])

# First, check for "--without-r" or "--with-r=no".
if test x"${RBIN}" = xno; then
AC_MSG_NOTICE([Disabling R])
RBIN=
else

# can we find R?
if test "x$RBIN" = xyes; then
   AC_PATH_PROG(RBIN, R)
fi
fi

AC_SUBST(RBIN)

#----------------------------------------------------------------
# Look for Go compilers
#----------------------------------------------------------------

AC_ARG_WITH(go, AS_HELP_STRING([--without-go], [Disable Go])
AS_HELP_STRING([--with-go=path], [Set location of Go compiler]),[GOBIN="$withval"], [GOBIN="$alllang_default"])

if test x"${GOBIN}" = xno; then
  AC_MSG_NOTICE([Disabling Go])
  GO=
  GOGCC=false
  GCCGO=
  GOOPT=
  GCCGOOPT=
  GOVERSIONOPTION=
else

  if test "x$GOBIN" = xyes; then
    AC_CHECK_PROGS(GO, go)
  else
    GO="$GOBIN"
  fi

  GOGCC=false
  GCCGO=
  GOOPT=
  GCCGOOPT=
  GOVERSIONOPTION=

  if test -n "$GO" ; then
    GOVERSIONOPTION=version
    go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //')
    AC_MSG_CHECKING([whether go version is too old])
    case $go_version in
    go1.[012]*)
      AC_MSG_RESULT([yes - minimum version is 1.3])
      GO=
      ;;
    *)
      AC_MSG_RESULT([no])
      ;;
    esac
  fi

  AC_CHECK_PROGS(GCCGO, gccgo)

  if test -n "$GCCGO" ; then
    if $GCCGO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then
      AC_MSG_CHECKING([whether gccgo version is too old])
      go_version=[`$GO $GOVERSIONOPTION | sed -n '1p' | sed -e 's/^.* \([0-9.]*\) *$/\1/' -e 's/[.]//g'`]
      if test "x$go_version" = x; then
        AC_MSG_RESULT([could not determine gccgo version])
        GCCGO=
      elif test "$go_version" -lt 470; then
        AC_MSG_RESULT([yes - minimum version is 4.7.0])
        GCCGO=
      else
        AC_MSG_RESULT([no])
        if test "$go_version" -lt 480; then
          GCCGOOPT="-intgosize 32"
        fi
      fi
    fi
  fi
fi

AC_SUBST(GOGCC)
AC_SUBST(GCCGO)
AC_SUBST(GO)
AC_SUBST(GOC)
AC_SUBST(GO1)
AC_SUBST(GO12)
AC_SUBST(GO13)
AC_SUBST(GO15)
AC_SUBST(GOOPT)
AC_SUBST(GCCGOOPT)
AC_SUBST(GOVERSIONOPTION)

#----------------------------------------------------------------
# Look for D
#----------------------------------------------------------------

AC_ARG_WITH(d, AS_HELP_STRING([--without-d], [Disable D]), [with_d="$withval"], [with_d="$alllang_default"])
AC_ARG_WITH(d1-compiler, [  --with-d1-compiler=path  Set location of D1/Tango compiler (DMD compatible)],[D1COMPILERBIN="$withval"], [D1COMPILERBIN=])
AC_ARG_WITH(d2-compiler, [  --with-d2-compiler=path  Set location of D2 compiler (DMD compatible)],[D2COMPILERBIN="$withval"], [D2COMPILERBIN=])


# First, check for "--without-d" or "--with-d=no".
if test x"${with_d}" = xno; then
  AC_MSG_NOTICE([Disabling D])
  D1COMPILER=
  D2COMPILER=
else
  old_ac_ext=$ac_ext
  ac_ext=d

  if test -z "$D1COMPILERBIN" ; then
    AC_CHECK_PROGS(D1COMPILER, dmd ldmd gdmd)

    if test -n "$D1COMPILER" ; then
      AC_MSG_CHECKING(whether the D1/Tango compiler works)
      cat > conftest.$ac_ext <<_ACEOF
import tango.io.Stdout;
void main() {
}
_ACEOF
      rm -f conftest.$ac_objext
      AS_IF(
        [$D1COMPILER conftest.$ac_ext 2>&AS_MESSAGE_LOG_FD && test ! -s conftest.err && test -s conftest.$ac_objext],
        [AC_MSG_RESULT([yes])],
        [_AC_MSG_LOG_CONFTEST AC_MSG_RESULT([no])
        D1COMPILER=]
      )
      rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    fi
  else
    D1COMPILER="$D1COMPILERBIN"
  fi

  if test -z "$D2COMPILERBIN" ; then
    AC_CHECK_PROGS(D2COMPILER, dmd gdmd ldmd2 ldc2)

    if test -n "$D2COMPILER" ; then
      AC_MSG_CHECKING(whether the D2 compiler works)
      cat > conftest.$ac_ext <<_ACEOF
import std.algorithm;
void main() {
}
_ACEOF
      rm -f conftest.$ac_objext
      AS_IF(
        [$D2COMPILER conftest.$ac_ext 2>&AS_MESSAGE_LOG_FD && test ! -s conftest.err && test -s conftest.$ac_objext],
        [AC_MSG_RESULT([yes])],
        [_AC_MSG_LOG_CONFTEST AC_MSG_RESULT([no])
        D2COMPILER=]
      )
      rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    fi
  else
    D2COMPILER="$D2COMPILERBIN"
  fi

  ac_ext=$old_ac_ext
fi

if test -n "$D1COMPILER"; then
  DDEFAULTVERSION=1
elif test -n "$D2COMPILER"; then
  DDEFAULTVERSION=2
fi

# Do not prefix library file names with "lib" on Windows.
case $host in
*-*-cygwin* | *-*-mingw*) DLIBPREFIX="";;
*)DLIBPREFIX="lib";;
esac

AC_SUBST(D1COMPILER)
AC_SUBST(D2COMPILER)
AC_SUBST(DDEFAULTVERSION)
AC_SUBST(DLIBPREFIX)

#----------------------------------------------------------------
# Determine which languages to use for examples/test-suite
#----------------------------------------------------------------

SKIP_TCL=
if test -z "$TCLINCLUDE" || test -z "$TCLLIB" ; then
    SKIP_TCL="1"
fi
AC_SUBST(SKIP_TCL)


SKIP_PERL5=
if test -z "$PERL" || test -z "$PERL5EXT" || test -z "$PERL5TESTMORE"; then
    SKIP_PERL5="1"
fi
AC_SUBST(SKIP_PERL5)


SKIP_OCTAVE=
if test -z "$OCTAVE" ; then
    SKIP_OCTAVE="1"
fi
AC_SUBST(SKIP_OCTAVE)


SKIP_PYTHON=
if (test -z "$PYINCLUDE" || test -z "$PYLINK") &&
   (test -z "$PY3INCLUDE" || test -z "$PY3LINK") ; then
    SKIP_PYTHON="1"
fi
AC_SUBST(SKIP_PYTHON)

SKIP_PYTHON3=
if test -z "$PY3INCLUDE" || test -z "$PY3LINK" ; then
    SKIP_PYTHON3="1"
fi
AC_SUBST(SKIP_PYTHON3)

SKIP_JAVA=
if test -z "$JAVA" || test -z "$JAVAC" || test -z "$JAVAINC" ; then
    SKIP_JAVA="1"
fi
AC_SUBST(SKIP_JAVA)

SKIP_JAVASCRIPT=
if test -z "$JAVASCRIPT" || ( test -z "$NODEJS" && test -z "$JSCENABLED" && test -z "$JSV8ENABLED" ) ; then
    SKIP_JAVASCRIPT="1"
fi
AC_SUBST(SKIP_JAVASCRIPT)

SKIP_GUILE=
if test -z "$GUILE" || test -z "$GUILE_LIBS" ; then
    SKIP_GUILE="1"
fi
AC_SUBST(SKIP_GUILE)


SKIP_MZSCHEME=
if test -z "$MZC" || test -z "$MZDYNOBJ" ; then
    SKIP_MZSCHEME="1"
fi
AC_SUBST(SKIP_MZSCHEME)


SKIP_RUBY=
if test -z "$RUBY" || test -z "$RUBYINCLUDE" || test -z "$RUBYLIB" ; then
    SKIP_RUBY="1"
fi
AC_SUBST(SKIP_RUBY)


SKIP_PHP=
if test -z "$PHP" || test -z "$PHPINC" ; then
    SKIP_PHP="1"
fi
AC_SUBST(SKIP_PHP)


SKIP_OCAML=
if test -z "$OCAMLC" || test -z "$CAMLP4" ; then
    SKIP_OCAML="1"
fi
AC_SUBST(SKIP_OCAML)


SKIP_CSHARP=
if test -z "$CSHARPCOMPILER" ; then
    SKIP_CSHARP="1"
else
    if test "cscc" = "$CSHARPCOMPILER" && test -z "$CSHARPCILINTERPRETER" ; then
      SKIP_CSHARP="1"
    fi
fi
AC_SUBST(SKIP_CSHARP)

SKIP_LUA=
# we need LUABIN & dynamic loading
if test -z "$LUABIN" || test -z "$LUADYNAMICLOADLIB"; then
    SKIP_LUA="1"
fi
AC_SUBST(SKIP_LUA)

SKIP_R=
if test -z "$RBIN" ; then
    SKIP_R="1"
fi
AC_SUBST(SKIP_R)

SKIP_SCILAB=
if test -z "$SCILAB"; then
    SKIP_SCILAB="1"
fi
AC_SUBST(SKIP_SCILAB)

SKIP_GO=
if test -z "$GO" ; then
    SKIP_GO="1"
fi
AC_SUBST(SKIP_GO)

SKIP_D=
if test -z "$DDEFAULTVERSION" ; then
    SKIP_D="1"
fi
AC_SUBST(SKIP_D)

#----------------------------------------------------------------
# Additional language dependencies
#----------------------------------------------------------------

SKIP_ANDROID=
if test -z "$ANDROID" || test -z "$ADB" || test -z "$ANT" || test -z "$NDKBUILD" ; then
    SKIP_ANDROID="1"
fi
AC_SUBST(SKIP_ANDROID)



#----------------------------------------------------------------
# Miscellaneous
#----------------------------------------------------------------

ABS_SRCDIR=`(cd ${srcdir} && pwd)`

dnl Under Cygwin, we may need native absolute path as it is used by SWIG, which
dnl may be a native, and not a Cygwin, program (this is the case when it's
dnl built using MinGW or cccl compiler in Cygwin environment). However it may,
dnl although this is probably more rare, also be built as a Cygwin program.
dnl Using "mixed" path like we do here allows the path to work in both cases.
case $host in
  *-*-mingw* ) ABS_SRCDIR=`${srcdir}/Tools/convertpath -m $ABS_SRCDIR` ;;
  *-*-cygwin* ) ABS_SRCDIR=`cygpath --mixed $ABS_SRCDIR` ;;
esac

# Root directory
ROOT_DIR=`pwd`
case $host in
*-*-cygwin*)
  # Translate path for native Windows compilers for use with 'make check'
  if (cygpath --mixed $ROOT_DIR) >/dev/null 2>/dev/null; then
    ROOT_DIR=`cygpath --mixed $ROOT_DIR`
  fi
  ;;
esac

case $host in
*-*-cygwin* | *-*-mingw*)
  # Extra files generated by some Windows compilers
  EXTRA_CLEAN="*.stackdump *.exp *.lib *.pdb *.ilk"
  ;;
esac

AC_SUBST(ROOT_DIR)
AC_SUBST(EXTRA_CLEAN)
AC_SUBST(ac_aux_dir)

# Configure SWIG_LIB path

AC_ARG_WITH(swiglibdir,[  --with-swiglibdir=DIR   Put SWIG system-independent libraries into DIR.],
  [swig_lib="$withval"], [swig_lib="${datadir}/swig/${PACKAGE_VERSION}"])
SWIG_LIB_INSTALL=${swig_lib}
AC_SUBST(SWIG_LIB_INSTALL)
AC_DEFINE_DIR(SWIG_LIB, swig_lib, [Directory for SWIG system-independent libraries])

case $build in
  # Windows does not understand unix directories. Convert into a windows directory with drive letter.
  *-*-mingw*) SWIG_LIB_WIN_UNIX=`${srcdir}/Tools/convertpath -m $SWIG_LIB`;;
  *-*-cygwin*) SWIG_LIB_WIN_UNIX=`cygpath --mixed "$SWIG_LIB"`;;
  *) SWIG_LIB_WIN_UNIX="";;
esac
AC_DEFINE_UNQUOTED(SWIG_LIB_WIN_UNIX, ["$SWIG_LIB_WIN_UNIX"], [Directory for SWIG system-independent libraries (Unix install on native Windows)])

SWIG_LIB_PREINST=$ABS_SRCDIR/Lib
AC_SUBST(SWIG_LIB_PREINST)

dnl For testing purposes, clear SWIG_LIB when building SWIG in the source
dnl directory under Windows because it is supposed to work without SWIG_LIB
dnl being set. Otherwise it always needs to be set.
SWIG_LIB_SET="env SWIG_LIB=\$(SWIG_LIB_DIR)"
if test "${srcdir}" = "."; then
    AC_EGREP_CPP([yes],
    [#ifdef _WIN32
     yes
    #endif
    ], [SWIG_LIB_SET="env SWIG_LIB="], [])
fi
AC_SUBST(SWIG_LIB_SET)

AC_CONFIG_FILES([
    Makefile
    swig.spec
    Examples/Makefile
    Examples/d/example.mk
    Examples/xml/Makefile
    Examples/test-suite/errors/Makefile
    Examples/test-suite/csharp/Makefile
    Examples/test-suite/d/Makefile
    Examples/test-suite/guile/Makefile
    Examples/test-suite/java/Makefile
    Examples/test-suite/javascript/Makefile
    Examples/test-suite/mzscheme/Makefile
    Examples/test-suite/ocaml/Makefile
    Examples/test-suite/octave/Makefile
    Examples/test-suite/perl5/Makefile
    Examples/test-suite/php/Makefile
    Examples/test-suite/python/Makefile
    Examples/test-suite/ruby/Makefile
    Examples/test-suite/scilab/Makefile
    Examples/test-suite/tcl/Makefile
    Examples/test-suite/lua/Makefile
    Examples/test-suite/r/Makefile
    Examples/test-suite/go/Makefile
    Source/Makefile
    Tools/javascript/Makefile
])
AC_CONFIG_FILES([preinst-swig], [chmod +x preinst-swig])
AC_CONFIG_FILES([CCache/ccache_swig_config.h])

#--------------------------------------------------------------------
# Building Examples/ out of source directory
#--------------------------------------------------------------------

# If building out of source tree, replicate Examples/ source tree in
# build directory, and copy over Makefiles from source directory.
# Prefix each Makefile with a header which sets SRCDIR to the relative
# source directory, and provides a rule for updating the Makefile from
# its original source.
AC_CONFIG_COMMANDS([Examples],[
  if test "x${srcdir}" != "x." ; then
    AC_MSG_NOTICE([generating Examples build tree])
    for mkfile in `cd ${srcdir} && find Examples/ -type f -name Makefile`; do
      dir=`dirname ${mkfile}`
      d=${dir}
      reldir=""
      while test "x$d" != "x." ; do
        d=`dirname $d`
        reldir="${reldir}../"
      done
      relsrcdir=${reldir}${srcdir}/
      AS_MKDIR_P([${dir}])
      cat <<EOF >${mkfile}
# DO NOT EDIT: instead edit ${relsrcdir}${mkfile}
# and run (cd ${reldir} && ./config.status) to regenerate
TOP_BUILDDIR_TO_TOP_SRCDIR = ${srcdir}/
SRCDIR = ${relsrcdir}${dir}/

EOF
      cat ${srcdir}/${mkfile} >>${mkfile}
    done
  fi
])

#--------------------------------------------------------------------

AC_OUTPUT

langs=""
test -n "$SKIP_CSHARP"		|| langs="${langs}csharp "
test -n "$SKIP_D"		|| langs="${langs}d "
test -n "$SKIP_GO"		|| langs="${langs}go "
test -n "$SKIP_GUILE"		|| langs="${langs}guile "
test -n "$SKIP_JAVA"		|| langs="${langs}java "
test -n "$SKIP_JAVASCRIPT"	|| langs="${langs}javascript "
test -n "$SKIP_LUA"		|| langs="${langs}lua "
test -n "$SKIP_MZSCHEME"	|| langs="${langs}mzscheme "
test -n "$SKIP_OCAML"		|| langs="${langs}ocaml "
test -n "$SKIP_OCTAVE"		|| langs="${langs}octave "
test -n "$SKIP_PERL5"		|| langs="${langs}perl5 "
test -n "$SKIP_PHP"		|| langs="${langs}php "
test -n "$SKIP_PYTHON"		|| langs="${langs}python "
test -n "$SKIP_R"		|| langs="${langs}r "
test -n "$SKIP_RUBY"		|| langs="${langs}ruby "
test -n "$SKIP_SCILAB"		|| langs="${langs}scilab "
test -n "$SKIP_TCL"		|| langs="${langs}tcl "

echo "
The SWIG test-suite and examples are configured for the following languages:
$langs
"

dnl configure.ac ends here