summaryrefslogtreecommitdiff
path: root/src/configure.in
blob: 3b867e5f5b170ed0c8409cdbd83a841100a9be67 (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
dnl configure.in: autoconf script for Vim

dnl Process this file with autoconf 2.12 or 2.13 to produce "configure".
dnl Should also work with autoconf 2.54 and later.

AC_INIT(vim.h)
AC_CONFIG_HEADER(auto/config.h:config.h.in)

dnl Being able to run configure means the system is Unix (compatible).
AC_DEFINE(UNIX)
AC_PROG_MAKE_SET

dnl Checks for programs.
AC_PROG_CC	dnl required by almost everything
AC_PROG_CPP	dnl required by header file checks
AC_PROGRAM_EGREP dnl required by AC_EGREP_CPP
AC_ISC_POSIX	dnl required by AC_C_CROSS
AC_PROG_AWK	dnl required for "make html" in ../doc

dnl Don't strip if we don't have it
AC_CHECK_PROG(STRIP, strip, strip, :)

dnl Check for extension of executables
AC_EXEEXT

dnl Set default value for CFLAGS if none is defined or it's empty
if test -z "$CFLAGS"; then
  CFLAGS="-O"
  test "$GCC" = yes && CFLAGS="-O2 -fno-strength-reduce -Wall"
fi
if test "$GCC" = yes; then
  dnl method that should work for nearly all versions
  gccversion=`"$CC" -dumpversion`
  if test "x$gccversion" = "x"; then
    dnl old method; fall-back for when -dumpversion doesn't work
    gccversion=`"$CC" --version | sed -e '2,$d' -e 's/darwin.//' -e 's/^[[^0-9]]*\([[0-9]]\.[[0-9.]]*\).*$/\1/g'`
  fi
  dnl version 4.0.1 was reported to cause trouble on Macintosh by Marcin Dalecki
  if test "$gccversion" = "3.0.1" -o "$gccversion" = "3.0.2" -o "$gccversion" = "4.0.1"; then
    echo 'GCC [[34]].0.[[12]] has a bug in the optimizer, disabling "-O#"'
    CFLAGS=`echo "$CFLAGS" | sed 's/-O[[23456789]]/-O/'`
  else
    if test "$gccversion" = "3.1" -o "$gccversion" = "3.2" -o "$gccversion" = "3.2.1" && `echo "$CFLAGS" | grep -v fno-strength-reduce >/dev/null`; then
      echo 'GCC 3.1 and 3.2 have a bug in the optimizer, adding "-fno-strength-reduce"'
      CFLAGS="$CFLAGS -fno-strength-reduce"
    fi
  fi
fi

dnl If configure thinks we are cross compiling, there is probably something
dnl wrong with the CC or CFLAGS settings, give an understandable error message
if test "$cross_compiling" = yes; then
  AC_MSG_ERROR([cannot compile a simple program, check CC and CFLAGS
  (cross compiling doesn't work)])
fi

dnl gcc-cpp has the wonderful -MM option to produce nicer dependencies.
dnl But gcc 3.1 changed the meaning!  See near the end.
test "$GCC" = yes && CPP_MM=M; AC_SUBST(CPP_MM)

if test -f ./toolcheck; then
  AC_CHECKING(for buggy tools)
  sh ./toolcheck 1>&AC_FD_MSG
fi

OS_EXTRA_SRC=""; OS_EXTRA_OBJ=""

dnl Check for BeOS, which needs an extra source file
AC_MSG_CHECKING(for BeOS)
case `uname` in
    BeOS)	OS_EXTRA_SRC=os_beos.c; OS_EXTRA_OBJ=objects/os_beos.o
		BEOS=yes; AC_MSG_RESULT(yes);;
    *)		BEOS=no; AC_MSG_RESULT(no);;
esac

dnl If QNX is found, assume we don't want to use Xphoton
dnl unless it was specifically asked for (--with-x)
AC_MSG_CHECKING(for QNX)
case `uname` in
    QNX)	OS_EXTRA_SRC=os_qnx.c; OS_EXTRA_OBJ=objects/os_qnx.o
		test -z "$with_x" && with_x=no
		QNX=yes; AC_MSG_RESULT(yes);;
    *)		QNX=no; AC_MSG_RESULT(no);;
esac

dnl Check for Darwin and MacOS X
dnl We do a check for MacOS X in the very beginning because there
dnl are a lot of other things we need to change besides GUI stuff
AC_MSG_CHECKING([for Darwin (Mac OS X)])
if test "`(uname) 2>/dev/null`" = Darwin; then
  AC_MSG_RESULT(yes)

  AC_MSG_CHECKING(--disable-darwin argument)
  AC_ARG_ENABLE(darwin,
	  [  --disable-darwin        Disable Darwin (Mac OS X) support.],
	  , [enable_darwin="yes"])
  if test "$enable_darwin" = "yes"; then
    AC_MSG_RESULT(no)
    AC_MSG_CHECKING(if Darwin files are there)
    if test -f os_macosx.c; then
      AC_MSG_RESULT(yes)
    else
      AC_MSG_RESULT([no, Darwin support disabled])
      enable_darwin=no
    fi
  else
    AC_MSG_RESULT([yes, Darwin support excluded])
  fi

  AC_MSG_CHECKING(--with-mac-arch argument)
  AC_ARG_WITH(mac-arch, [  --with-mac-arch=ARCH    current, intel, ppc or both],
	MACARCH="$withval"; AC_MSG_RESULT($MACARCH),
	MACARCH="current"; AC_MSG_RESULT(defaulting to $MACARCH))

  if test "x$MACARCH" = "xboth"; then
    AC_MSG_CHECKING(for 10.4 universal SDK)
    dnl There is a terrible inconsistency (but we appear to get away with it):
    dnl $CFLAGS uses the 10.4u SDK library for the headers, while $CPPFLAGS
    dnl doesn't, because "gcc -E" doesn't grok it.  That means the configure
    dnl tests using the preprocessor are actually done with the wrong header
    dnl files. $LDFLAGS is set at the end, because configure uses it together
    dnl with $CFLAGS and we can only have one -sysroot argument.
    save_cppflags="$CPPFLAGS"
    save_cflags="$CFLAGS"
    save_ldflags="$LDFLAGS"
    CFLAGS="$CFLAGS -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
    AC_TRY_LINK([ ], [ ],
	AC_MSG_RESULT(found, will make universal binary),

	AC_MSG_RESULT(not found)
	CFLAGS="$save_cflags"
	AC_MSG_CHECKING(if Intel architecture is supported)
	CPPFLAGS="$CPPFLAGS -arch i386"
	LDFLAGS="$save_ldflags -arch i386"
	AC_TRY_LINK([ ], [ ],
	    AC_MSG_RESULT(yes); MACARCH="intel",
	    AC_MSG_RESULT(no, using PowerPC)
	        MACARCH="ppc"
		CPPFLAGS="$save_cppflags -arch ppc"
		LDFLAGS="$save_ldflags -arch ppc"))
  elif test "x$MACARCH" = "xintel"; then
    CPPFLAGS="$CPPFLAGS -arch intel"
    LDFLAGS="$LDFLAGS -arch intel"
  elif test "x$MACARCH" = "xppc"; then
    CPPFLAGS="$CPPFLAGS -arch ppc"
    LDFLAGS="$LDFLAGS -arch ppc"
  fi

  if test "$enable_darwin" = "yes"; then
    MACOSX=yes
    OS_EXTRA_SCR="os_macosx.c os_mac_conv.c";
    OS_EXTRA_OBJ="objects/os_macosx.o objects/os_mac_conv.o"
    dnl TODO: use -arch i386 on Intel machines
    CPPFLAGS="$CPPFLAGS -DMACOS_X_UNIX -no-cpp-precomp"
    if test "x$MACARCH" = "xboth"; then
      CPPFLAGS="$CPPFLAGS -I/Developer/SDKs/MacOSX10.4u.sdk/Developer/Headers/FlatCarbon"
    else
      CPPFLAGS="$CPPFLAGS -I/Developer/Headers/FlatCarbon"
    fi

    dnl If Carbon is found, assume we don't want X11
    dnl unless it was specifically asked for (--with-x)
    dnl or Motif, Athena or GTK GUI is used.
    AC_CHECK_HEADER(Carbon/Carbon.h, CARBON=yes)
    if test "x$CARBON" = "xyes"; then
      if test -z "$with_x" -a "X$enable_gui" != Xmotif -a "X$enable_gui" != Xathena -a "X$enable_gui" != Xgtk -a "X$enable_gui" != Xgtk2; then
	with_x=no

	dnl Default install directory is not /usr/local
	if test x$prefix = xNONE; then
	  prefix=/Applications
	fi

	dnl Sorry for the hard coded default
	datadir='${prefix}/Vim.app/Contents/Resources'
      fi
    fi
  fi

  dnl Avoid a bug with -O2 with gcc 4.0.1.  Symptom: malloc() reports double
  dnl free.  This happens in expand_filename(), because the optimizer swaps
  dnl two blocks of code, both using "repl", that can't be swapped.
  if test "$MACARCH" = "intel" -o "$MACARCH" = "both"; then
    CFLAGS=`echo "$CFLAGS" | sed 's/-O[[23456789]]/-Oz/'`
  fi

else
  AC_MSG_RESULT(no)
fi

AC_SUBST(OS_EXTRA_SRC)
AC_SUBST(OS_EXTRA_OBJ)

dnl Add /usr/local/lib to $LDFLAGS and /usr/local/include to CFLAGS.
dnl Only when the directory exists and it wasn't there yet.
dnl For gcc don't do this when it is already in the default search path.
have_local_include=''
have_local_lib=''
if test "$GCC" = yes; then
  echo 'void f(){}' > conftest.c
  dnl -no-cpp-precomp is needed for OS X 10.2 (Ben Fowler)
  have_local_include=`${CC-cc} -no-cpp-precomp -c -v conftest.c 2>&1 | grep '/usr/local/include'`
  have_local_lib=`${CC-cc} -c -v conftest.c 2>&1 | grep '/usr/local/lib'`
  rm -f conftest.c conftest.o
fi
if test -z "$have_local_lib" -a -d /usr/local/lib; then
  tt=`echo "$LDFLAGS" | sed -e 's+-L/usr/local/lib ++g' -e 's+-L/usr/local/lib$++g'`
  if test "$tt" = "$LDFLAGS"; then
    LDFLAGS="$LDFLAGS -L/usr/local/lib"
  fi
fi
if test -z "$have_local_include" -a -d /usr/local/include; then
  tt=`echo "$CPPFLAGS" | sed -e 's+-I/usr/local/include ++g' -e 's+-I/usr/local/include$++g'`
  if test "$tt" = "$CPPFLAGS"; then
    CPPFLAGS="$CPPFLAGS -I/usr/local/include"
  fi
fi

AC_MSG_CHECKING(--with-vim-name argument)
AC_ARG_WITH(vim-name, [  --with-vim-name=NAME    what to call the Vim executable],
	VIMNAME="$withval"; AC_MSG_RESULT($VIMNAME),
	VIMNAME="vim"; AC_MSG_RESULT(Defaulting to $VIMNAME))
AC_SUBST(VIMNAME)
AC_MSG_CHECKING(--with-ex-name argument)
AC_ARG_WITH(ex-name, [  --with-ex-name=NAME     what to call the Ex executable],
	EXNAME="$withval"; AC_MSG_RESULT($EXNAME),
	EXNAME="ex"; AC_MSG_RESULT(Defaulting to ex))
AC_SUBST(EXNAME)
AC_MSG_CHECKING(--with-view-name argument)
AC_ARG_WITH(view-name, [  --with-view-name=NAME   what to call the View executable],
	VIEWNAME="$withval"; AC_MSG_RESULT($VIEWNAME),
	VIEWNAME="view"; AC_MSG_RESULT(Defaulting to view))
AC_SUBST(VIEWNAME)

AC_MSG_CHECKING(--with-global-runtime argument)
AC_ARG_WITH(global-runtime, [  --with-global-runtime=DIR    global runtime directory in 'runtimepath'],
	AC_MSG_RESULT($withval); AC_DEFINE_UNQUOTED(RUNTIME_GLOBAL, "$withval"),
	AC_MSG_RESULT(no))

AC_MSG_CHECKING(--with-modified-by argument)
AC_ARG_WITH(modified-by, [  --with-modified-by=NAME       name of who modified a release version],
	AC_MSG_RESULT($withval); AC_DEFINE_UNQUOTED(MODIFIED_BY, "$withval"),
	AC_MSG_RESULT(no))

dnl Check for EBCDIC stolen from the LYNX port to OS390 Unix
AC_MSG_CHECKING(if character set is EBCDIC)
AC_TRY_COMPILE([ ],
[ /* TryCompile function for CharSet.
   Treat any failure as ASCII for compatibility with existing art.
   Use compile-time rather than run-time tests for cross-compiler
   tolerance.  */
#if '0'!=240
make an error "Character set is not EBCDIC"
#endif ],
[ # TryCompile action if true
cf_cv_ebcdic=yes ],
[ # TryCompile action if false
cf_cv_ebcdic=no])
# end of TryCompile ])
# end of CacheVal CvEbcdic
AC_MSG_RESULT($cf_cv_ebcdic)
case "$cf_cv_ebcdic" in  #(vi
    yes)	AC_DEFINE(EBCDIC)
		line_break='"\\n"'
		;;
    *)		line_break='"\\012"';;
esac
AC_SUBST(line_break)

if test "$cf_cv_ebcdic" = "yes"; then
dnl If we have EBCDIC we most likley have OS390 Unix, let's test it!
AC_MSG_CHECKING(for OS/390 Unix)
case `uname` in
    OS/390)	OS390Unix="yes";
		dnl If using cc the environment variable _CC_CCMODE must be
		dnl set to "1", so that some compiler extensions are enabled.
		dnl If using c89 the environment variable is named _CC_C89MODE.
		dnl Note: compile with c89 never tested.
		if test "$CC" = "cc"; then
		  ccm="$_CC_CCMODE"
		  ccn="CC"
		else
		  if test "$CC" = "c89"; then
		    ccm="$_CC_C89MODE"
		    ccn="C89"
		  else
		    ccm=1
		  fi
		fi
		if test "$ccm" != "1"; then
		  echo ""
		  echo "------------------------------------------"
		  echo " On OS/390 Unix, the environment variable"
		  echo " __CC_${ccn}MODE must be set to \"1\"!"
		  echo " Do:"
		  echo "    export _CC_${ccn}MODE=1"
		  echo " and then call configure again."
		  echo "------------------------------------------"
		  exit 1
		fi
		CFLAGS="$CFLAGS -D_ALL_SOURCE"; LDFLAGS="$LDFLAGS -Wl,EDIT=NO"
		AC_MSG_RESULT(yes)
		;;
    *)		OS390Unix="no";
		AC_MSG_RESULT(no)
		;;
esac
fi


dnl Check user requested features.

AC_MSG_CHECKING(--with-features argument)
AC_ARG_WITH(features, [  --with-features=TYPE    tiny, small, normal, big or huge (default: normal)],
	features="$withval"; AC_MSG_RESULT($features),
	features="normal"; AC_MSG_RESULT(Defaulting to normal))

dovimdiff=""
dogvimdiff=""
case "$features" in
  tiny)		AC_DEFINE(FEAT_TINY) ;;
  small)	AC_DEFINE(FEAT_SMALL) ;;
  normal)	AC_DEFINE(FEAT_NORMAL) dovimdiff="installvimdiff";
			dogvimdiff="installgvimdiff" ;;
  big)		AC_DEFINE(FEAT_BIG) dovimdiff="installvimdiff";
			dogvimdiff="installgvimdiff" ;;
  huge)		AC_DEFINE(FEAT_HUGE) dovimdiff="installvimdiff";
			dogvimdiff="installgvimdiff" ;;
  *)		AC_MSG_RESULT([Sorry, $features is not supported]) ;;
esac

AC_SUBST(dovimdiff)
AC_SUBST(dogvimdiff)

AC_MSG_CHECKING(--with-compiledby argument)
AC_ARG_WITH(compiledby, [  --with-compiledby=NAME  name to show in :version message],
	compiledby="$withval"; AC_MSG_RESULT($withval),
	compiledby=""; AC_MSG_RESULT(no))
AC_SUBST(compiledby)

AC_MSG_CHECKING(--disable-xsmp argument)
AC_ARG_ENABLE(xsmp,
	[  --disable-xsmp          Disable XSMP session management],
	, enable_xsmp="yes")

if test "$enable_xsmp" = "yes"; then
  AC_MSG_RESULT(no)
  AC_MSG_CHECKING(--disable-xsmp-interact argument)
  AC_ARG_ENABLE(xsmp-interact,
	  [  --disable-xsmp-interact Disable XSMP interaction],
	  , enable_xsmp_interact="yes")
  if test "$enable_xsmp_interact" = "yes"; then
    AC_MSG_RESULT(no)
    AC_DEFINE(USE_XSMP_INTERACT)
  else
    AC_MSG_RESULT(yes)
  fi
else
  AC_MSG_RESULT(yes)
fi

dnl Check for MzScheme feature.
AC_MSG_CHECKING(--enable-mzschemeinterp argument)
AC_ARG_ENABLE(mzschemeinterp,
	[  --enable-mzschemeinterp   Include MzScheme interpreter.], ,
	[enable_mzschemeinterp="no"])
AC_MSG_RESULT($enable_mzschemeinterp)

if test "$enable_mzschemeinterp" = "yes"; then
  dnl -- find the mzscheme executable
  AC_SUBST(vi_cv_path_mzscheme)

  AC_MSG_CHECKING(--with-plthome argument)
  AC_ARG_WITH(plthome,
  	[  --with-plthome=PLTHOME   Use PLTHOME.],
        with_plthome="$withval"; AC_MSG_RESULT($with_plthome),
	with_plthome="";AC_MSG_RESULT("no"))

  if test "X$with_plthome" != "X"; then
       vi_cv_path_mzscheme_pfx="$with_plthome"
  else
    AC_MSG_CHECKING(PLTHOME environment var)
    if test "X$PLTHOME" != "X"; then
	AC_MSG_RESULT("$PLTHOME")
        vi_cv_path_mzscheme_pfx="$PLTHOME"
    else
	AC_MSG_RESULT("not set")
	dnl -- try to find MzScheme executable
        AC_PATH_PROG(vi_cv_path_mzscheme, mzscheme)

	dnl resolve symbolic link, the executable is often elsewhere and there
	dnl are no links for the include files.
        if test "X$vi_cv_path_mzscheme" != "X"; then
	  lsout=`ls -l $vi_cv_path_mzscheme`
	  if echo "$lsout" | grep -e '->' >/dev/null 2>/dev/null; then
	    vi_cv_path_mzscheme=`echo "$lsout" | sed 's/.*-> \(.*\)/\1/'`
	  fi
	fi

        if test "X$vi_cv_path_mzscheme" != "X"; then
            dnl -- find where MzScheme thinks it was installed
            AC_CACHE_CHECK(MzScheme install prefix,vi_cv_path_mzscheme_pfx,
            [ vi_cv_path_mzscheme_pfx=`
      	    ${vi_cv_path_mzscheme} -evm \
            "(display (simplify-path		\
              (build-path (call-with-values	\
      	        (lambda () (split-path (find-system-path (quote exec-file)))) \
      	        (lambda (base name must-be-dir?) base)) (quote up))))"` ])
	    dnl Remove a trailing slash.
	    vi_cv_path_mzscheme_pfx=`echo "$vi_cv_path_mzscheme_pfx" | sed 's+/$++'`
        fi
    fi
  fi

  if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
    AC_MSG_CHECKING(if scheme.h can be found in $vi_cv_path_mzscheme_pfx/include)
    if test -f $vi_cv_path_mzscheme_pfx/include/scheme.h; then
      AC_MSG_RESULT("yes")
    else
      AC_MSG_RESULT("no")
      vi_cv_path_mzscheme_pfx=
    fi
  fi

  if test "X$vi_cv_path_mzscheme_pfx" != "X"; then
    if test -f "${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a"; then
      MZSCHEME_LIBS="${vi_cv_path_mzscheme_pfx}/lib/libmzgc.a ${vi_cv_path_mzscheme_pfx}/lib/libmzscheme.a"
    else
      MZSCHEME_LIBS="-L${vi_cv_path_mzscheme_pfx}/lib -lmzgc -lmzscheme"
      if test "$GCC" = yes; then
	dnl Make Vim remember the path to the library.  For when it's not in
	dnl $LD_LIBRARY_PATH.
        MZSCHEME_LIBS="$MZSCHEME_LIBS -Wl,-rpath -Wl,${vi_cv_path_mzscheme_pfx}/lib"
      elif test "`(uname) 2>/dev/null`" = SunOS &&
			       uname -r | grep '^5' >/dev/null; then
	MZSCHEME_LIBS="$MZSCHEME_LIBS -R ${vi_cv_path_mzscheme_pfx}/lib"
      fi
    fi
    MZSCHEME_CFLAGS="-I${vi_cv_path_mzscheme_pfx}/include   \
      -DMZSCHEME_COLLECTS='\"${vi_cv_path_mzscheme_pfx}/collects\"'"
    MZSCHEME_SRC="if_mzsch.c"
    MZSCHEME_OBJ="objects/if_mzsch.o"
    MZSCHEME_PRO="if_mzsch.pro"
    AC_DEFINE(FEAT_MZSCHEME)
  fi
  AC_SUBST(MZSCHEME_SRC)
  AC_SUBST(MZSCHEME_OBJ)
  AC_SUBST(MZSCHEME_PRO)
  AC_SUBST(MZSCHEME_LIBS)
  AC_SUBST(MZSCHEME_CFLAGS)
fi


AC_MSG_CHECKING(--enable-perlinterp argument)
AC_ARG_ENABLE(perlinterp,
	[  --enable-perlinterp     Include Perl interpreter.], ,
	[enable_perlinterp="no"])
AC_MSG_RESULT($enable_perlinterp)
if test "$enable_perlinterp" = "yes"; then
  AC_SUBST(vi_cv_path_perl)
  AC_PATH_PROG(vi_cv_path_perl, perl)
  if test "X$vi_cv_path_perl" != "X"; then
    AC_MSG_CHECKING(Perl version)
    if $vi_cv_path_perl -e 'require 5.003_01' >/dev/null 2>/dev/null; then
     eval `$vi_cv_path_perl -V:usethreads`
     if test "X$usethreads" = "XUNKNOWN" -o "X$usethreads" = "Xundef"; then
       badthreads=no
     else
       if $vi_cv_path_perl -e 'require 5.6.0' >/dev/null 2>/dev/null; then
	 eval `$vi_cv_path_perl -V:use5005threads`
	 if test "X$use5005threads" = "XUNKNOWN" -o "X$use5005threads" = "Xundef"; then
	   badthreads=no
	 else
	   badthreads=yes
	   AC_MSG_RESULT(>>> Perl > 5.6 with 5.5 threads cannot be used <<<)
	 fi
       else
	 badthreads=yes
	 AC_MSG_RESULT(>>> Perl 5.5 with threads cannot be used <<<)
       fi
     fi
     if test $badthreads = no; then
      AC_MSG_RESULT(OK)
      eval `$vi_cv_path_perl -V:shrpenv`
      if test "X$shrpenv" = "XUNKNOWN"; then # pre 5.003_04
	shrpenv=""
      fi
      vi_cv_perllib=`$vi_cv_path_perl -MConfig -e 'print $Config{privlibexp}'`
      AC_SUBST(vi_cv_perllib)
      dnl Remove "-fno-something", it breaks using cproto.
      perlcppflags=`$vi_cv_path_perl -Mlib=$srcdir -MExtUtils::Embed \
	      -e 'ccflags;perl_inc;print"\n"' | sed -e 's/-fno[[^ ]]*//'`
      dnl Remove "-lc", it breaks on FreeBSD when using "-pthread".
      perllibs=`cd $srcdir; $vi_cv_path_perl -MExtUtils::Embed -e 'ldopts' | \
		sed -e '/Warning/d' -e '/Note (probably harmless)/d' \
			-e 's/-bE:perl.exp//' -e 's/-lc //'`
      dnl Don't add perl lib to $LIBS: if it's not in LD_LIBRARY_PATH
      dnl a test in configure may fail because of that.
      perlldflags=`cd $srcdir; $vi_cv_path_perl -MExtUtils::Embed \
		-e 'ccdlflags' | sed -e 's/-bE:perl.exp//'`

      dnl check that compiling a simple program still works with the flags
      dnl added for Perl.
      AC_MSG_CHECKING([if compile and link flags for Perl are sane])
      cflags_save=$CFLAGS
      libs_save=$LIBS
      ldflags_save=$LDFLAGS
      CFLAGS="$CFLAGS $perlcppflags"
      LIBS="$LIBS $perllibs"
      LDFLAGS="$perlldflags $LDFLAGS"
      AC_TRY_LINK(,[ ],
	     AC_MSG_RESULT(yes); perl_ok=yes,
	     AC_MSG_RESULT(no: PERL DISABLED); perl_ok=no)
      CFLAGS=$cflags_save
      LIBS=$libs_save
      LDFLAGS=$ldflags_save
      if test $perl_ok = yes; then
	if test "X$perlcppflags" != "X"; then
	  PERL_CFLAGS="$perlcppflags"
	fi
	if test "X$perlldflags" != "X"; then
	  LDFLAGS="$perlldflags $LDFLAGS"
	fi
	PERL_LIBS=$perllibs
	PERL_SRC="auto/if_perl.c if_perlsfio.c"
	PERL_OBJ="objects/if_perl.o objects/if_perlsfio.o"
	PERL_PRO="if_perl.pro if_perlsfio.pro"
	AC_DEFINE(FEAT_PERL)
      fi
     fi
    else
      AC_MSG_RESULT(>>> too old; need Perl version 5.003_01 or later <<<)
    fi
  fi

  if test "x$MACOSX" = "xyes"; then
    dnl Mac OS X 10.2 or later
    dir=/System/Library/Perl
    darwindir=$dir/darwin
    if test -d $darwindir; then
      PERL=/usr/bin/perl
    else
      dnl Mac OS X 10.3
      dir=/System/Library/Perl/5.8.1
      darwindir=$dir/darwin-thread-multi-2level
      if test -d $darwindir; then
	PERL=/usr/bin/perl
      fi
    fi
    if test -n "$PERL"; then
      PERL_DIR="$dir"
      PERL_CFLAGS="-DFEAT_PERL -I$darwindir/CORE"
      PERL_OBJ="objects/if_perl.o objects/if_perlsfio.o $darwindir/auto/DynaLoader/DynaLoader.a"
      PERL_LIBS="-L$darwindir/CORE -lperl"
    fi
  fi
fi
AC_SUBST(shrpenv)
AC_SUBST(PERL_SRC)
AC_SUBST(PERL_OBJ)
AC_SUBST(PERL_PRO)
AC_SUBST(PERL_CFLAGS)
AC_SUBST(PERL_LIBS)

AC_MSG_CHECKING(--enable-pythoninterp argument)
AC_ARG_ENABLE(pythoninterp,
	[  --enable-pythoninterp   Include Python interpreter.], ,
	[enable_pythoninterp="no"])
AC_MSG_RESULT($enable_pythoninterp)
if test "$enable_pythoninterp" = "yes"; then
  dnl -- find the python executable
  AC_PATH_PROG(vi_cv_path_python, python)
  if test "X$vi_cv_path_python" != "X"; then

    dnl -- get its version number
    AC_CACHE_CHECK(Python version,vi_cv_var_python_version,
    [[vi_cv_var_python_version=`
	    ${vi_cv_path_python} -c 'import sys; print sys.version[:3]'`
    ]])

    dnl -- it must be at least version 1.4
    AC_MSG_CHECKING(Python is 1.4 or better)
    if ${vi_cv_path_python} -c \
	"import sys; sys.exit(${vi_cv_var_python_version} < 1.4)"
    then
      AC_MSG_RESULT(yep)

      dnl -- find where python thinks it was installed
      AC_CACHE_CHECK(Python's install prefix,vi_cv_path_python_pfx,
      [ vi_cv_path_python_pfx=`
	    ${vi_cv_path_python} -c \
		"import sys; print sys.prefix"` ])

      dnl -- and where it thinks it runs
      AC_CACHE_CHECK(Python's execution prefix,vi_cv_path_python_epfx,
      [ vi_cv_path_python_epfx=`
	    ${vi_cv_path_python} -c \
		"import sys; print sys.exec_prefix"` ])

      dnl -- python's internal library path

      AC_CACHE_VAL(vi_cv_path_pythonpath,
      [ vi_cv_path_pythonpath=`
	    unset PYTHONPATH;
	    ${vi_cv_path_python} -c \
		"import sys, string; print string.join(sys.path,':')"` ])

      dnl -- where the Python implementation library archives are

      AC_ARG_WITH(python-config-dir,
	[  --with-python-config-dir=PATH  Python's config directory],
	[ vi_cv_path_python_conf="${withval}" ] )

      AC_CACHE_CHECK(Python's configuration directory,vi_cv_path_python_conf,
      [
	vi_cv_path_python_conf=
	for path in "${vi_cv_path_python_pfx}" "${vi_cv_path_python_epfx}"; do
	  for subdir in lib share; do
	    d="${path}/${subdir}/python${vi_cv_var_python_version}/config"
	    if test -d "$d" && test -f "$d/config.c"; then
	      vi_cv_path_python_conf="$d"
	    fi
	  done
	done
      ])

      PYTHON_CONFDIR="${vi_cv_path_python_conf}"

      if test "X$PYTHON_CONFDIR" = "X"; then
	AC_MSG_RESULT([can't find it!])
      else

	dnl -- we need to examine Python's config/Makefile too
	dnl    see what the interpreter is built from
	AC_CACHE_VAL(vi_cv_path_python_plibs,
	[
	    tmp_mkf="/tmp/Makefile-conf$$"
	    cat ${PYTHON_CONFDIR}/Makefile - <<'eof' >${tmp_mkf}
__:
	@echo "python_MODLIBS='$(MODLIBS)'"
	@echo "python_LIBS='$(LIBS)'"
	@echo "python_SYSLIBS='$(SYSLIBS)'"
	@echo "python_LINKFORSHARED='$(LINKFORSHARED)'"
eof
	    dnl -- delete the lines from make about Entering/Leaving directory
	    eval "`cd ${PYTHON_CONFDIR} && make -f ${tmp_mkf} __ | sed '/ directory /d'`"
	    rm -f ${tmp_mkf}
	    if test "x$MACOSX" = "xyes" && ${vi_cv_path_python} -c \
		"import sys; sys.exit(${vi_cv_var_python_version} < 2.3)"; then
	      vi_cv_path_python_plibs="-framework Python"
	    else
	      if test "${vi_cv_var_python_version}" = "1.4"; then
		  vi_cv_path_python_plibs="${PYTHON_CONFDIR}/libModules.a ${PYTHON_CONFDIR}/libPython.a ${PYTHON_CONFDIR}/libObjects.a ${PYTHON_CONFDIR}/libParser.a"
	      else
		  vi_cv_path_python_plibs="-L${PYTHON_CONFDIR} -lpython${vi_cv_var_python_version}"
	      fi
	      vi_cv_path_python_plibs="${vi_cv_path_python_plibs} ${python_MODLIBS} ${python_LIBS} ${python_SYSLIBS} ${python_LINKFORSHARED}"
	      dnl remove -ltermcap, it can conflict with an earlier -lncurses
	      vi_cv_path_python_plibs=`echo $vi_cv_path_python_plibs | sed s/-ltermcap//`
	    fi
	])

	PYTHON_LIBS="${vi_cv_path_python_plibs}"
	if test "${vi_cv_path_python_pfx}" = "${vi_cv_path_python_epfx}"; then
	  PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version}"
	else
	  PYTHON_CFLAGS="-I${vi_cv_path_python_pfx}/include/python${vi_cv_var_python_version} -I${vi_cv_path_python_epfx}/include/python${vi_cv_var_python_version}"
	fi
	PYTHON_SRC="if_python.c"
	dnl For Mac OSX 10.2 config.o is included in the Python library.
	if test "x$MACOSX" = "xyes"; then
	  PYTHON_OBJ="objects/if_python.o"
	else
	  PYTHON_OBJ="objects/if_python.o objects/py_config.o"
	fi
	if test "${vi_cv_var_python_version}" = "1.4"; then
	   PYTHON_OBJ="$PYTHON_OBJ objects/py_getpath.o"
	fi
	PYTHON_GETPATH_CFLAGS="-DPYTHONPATH='\"${vi_cv_path_pythonpath}\"' -DPREFIX='\"${vi_cv_path_python_pfx}\"' -DEXEC_PREFIX='\"${vi_cv_path_python_epfx}\"'"

	dnl On FreeBSD linking with "-pthread" is required to use threads.
	dnl _THREAD_SAFE must be used for compiling then.
	dnl The "-pthread" is added to $LIBS, so that the following check for
	dnl sigaltstack() will look in libc_r (it's there in libc!).
	dnl Otherwise, when using GCC, try adding -pthread to $CFLAGS.  GCC
	dnl will then define target-specific defines, e.g., -D_REENTRANT.
	dnl Don't do this for Mac OSX, -pthread will generate a warning.
	AC_MSG_CHECKING([if -pthread should be used])
	threadsafe_flag=
	thread_lib=
	if test "x$MACOSX" != "xyes"; then
	  test "$GCC" = yes && threadsafe_flag="-pthread"
	  if test "`(uname) 2>/dev/null`" = FreeBSD; then
	    threadsafe_flag="-D_THREAD_SAFE"
	    thread_lib="-pthread"
	  fi
	fi
	libs_save_old=$LIBS
	if test -n "$threadsafe_flag"; then
	  cflags_save=$CFLAGS
	  CFLAGS="$CFLAGS $threadsafe_flag"
	  LIBS="$LIBS $thread_lib"
	  AC_TRY_LINK(,[ ],
	     AC_MSG_RESULT(yes); PYTHON_CFLAGS="$PYTHON_CFLAGS $threadsafe_flag",
	     AC_MSG_RESULT(no); LIBS=$libs_save_old
	     )
	  CFLAGS=$cflags_save
	else
	  AC_MSG_RESULT(no)
	fi

	dnl check that compiling a simple program still works with the flags
	dnl added for Python.
	AC_MSG_CHECKING([if compile and link flags for Python are sane])
	cflags_save=$CFLAGS
	libs_save=$LIBS
	CFLAGS="$CFLAGS $PYTHON_CFLAGS"
	LIBS="$LIBS $PYTHON_LIBS"
	AC_TRY_LINK(,[ ],
	       AC_MSG_RESULT(yes); python_ok=yes,
	       AC_MSG_RESULT(no: PYTHON DISABLED); python_ok=no)
	CFLAGS=$cflags_save
	LIBS=$libs_save
	if test $python_ok = yes; then
	  AC_DEFINE(FEAT_PYTHON)
	else
	  LIBS=$libs_save_old
	  PYTHON_SRC=
	  PYTHON_OBJ=
	  PYTHON_LIBS=
	  PYTHON_CFLAGS=
	fi

      fi
    else
      AC_MSG_RESULT(too old)
    fi
  fi
fi
AC_SUBST(PYTHON_CONFDIR)
AC_SUBST(PYTHON_LIBS)
AC_SUBST(PYTHON_GETPATH_CFLAGS)
AC_SUBST(PYTHON_CFLAGS)
AC_SUBST(PYTHON_SRC)
AC_SUBST(PYTHON_OBJ)

AC_MSG_CHECKING(--enable-tclinterp argument)
AC_ARG_ENABLE(tclinterp,
	[  --enable-tclinterp      Include Tcl interpreter.], ,
	[enable_tclinterp="no"])
AC_MSG_RESULT($enable_tclinterp)

if test "$enable_tclinterp" = "yes"; then

  dnl on FreeBSD tclsh is a silly script, look for tclsh8.[420]
  AC_MSG_CHECKING(--with-tclsh argument)
  AC_ARG_WITH(tclsh, [  --with-tclsh=PATH       which tclsh to use (default: tclsh8.0)],
	tclsh_name="$withval"; AC_MSG_RESULT($tclsh_name),
	tclsh_name="tclsh8.4"; AC_MSG_RESULT(no))
  AC_PATH_PROG(vi_cv_path_tcl, $tclsh_name)
  AC_SUBST(vi_cv_path_tcl)

  dnl when no specific version specified, also try 8.2 and 8.0
  if test "X$vi_cv_path_tcl" = "X" -a $tclsh_name = "tclsh8.4"; then
    tclsh_name="tclsh8.2"
    AC_PATH_PROG(vi_cv_path_tcl, $tclsh_name)
  fi
  if test "X$vi_cv_path_tcl" = "X" -a $tclsh_name = "tclsh8.2"; then
    tclsh_name="tclsh8.0"
    AC_PATH_PROG(vi_cv_path_tcl, $tclsh_name)
  fi
  dnl still didn't find it, try without version number
  if test "X$vi_cv_path_tcl" = "X"; then
    tclsh_name="tclsh"
    AC_PATH_PROG(vi_cv_path_tcl, $tclsh_name)
  fi
  if test "X$vi_cv_path_tcl" != "X"; then
    AC_MSG_CHECKING(Tcl version)
    if echo 'exit [[expr [info tclversion] < 8.0]]' | $vi_cv_path_tcl - ; then
      tclver=`echo 'puts [[info tclversion]]' | $vi_cv_path_tcl -`
      AC_MSG_RESULT($tclver - OK);
      tclloc=`echo 'set l [[info library]];set i [[string last lib $l]];incr i -2;puts [[string range $l 0 $i]]' | $vi_cv_path_tcl -`

      AC_MSG_CHECKING(for location of Tcl include)
      if test "x$MACOSX" != "xyes"; then
	tclinc="$tclloc/include $tclloc/include/tcl $tclloc/include/tcl$tclver /usr/local/include /usr/include"
      else
	dnl For Mac OS X 10.3, use the OS-provided framework location
	tclinc="/System/Library/Frameworks/Tcl.framework/Headers"
      fi
      for try in $tclinc; do
	if test -f "$try/tcl.h"; then
	  AC_MSG_RESULT($try/tcl.h)
	  TCL_INC=$try
	  break
	fi
      done
      if test -z "$TCL_INC"; then
	AC_MSG_RESULT(<not found>)
	SKIP_TCL=YES
      fi
      if test -z "$SKIP_TCL"; then
	AC_MSG_CHECKING(for location of tclConfig.sh script)
	if test "x$MACOSX" != "xyes"; then
	  tclcnf=`echo $tclinc | sed s/include/lib/g`
	else
	  dnl For Mac OS X 10.3, use the OS-provided framework location
	  tclcnf="/System/Library/Frameworks/Tcl.framework"
	fi
	for try in $tclcnf; do
	  if test -f $try/tclConfig.sh; then
	    AC_MSG_RESULT($try/tclConfig.sh)
	    . $try/tclConfig.sh
	    dnl use eval, because tcl 8.2 includes ${TCL_DBGX}
	    TCL_LIBS=`eval echo "$TCL_LIB_SPEC $TCL_LIBS"`
	    dnl Use $TCL_DEFS for -D_THREAD_SAFE et al.  But only use the
	    dnl "-D_ABC" items.  Watch out for -DFOO=long\ long.
	    TCL_DEFS=`echo $TCL_DEFS | sed -e 's/\\\\ /\\\\X/g' | tr ' ' '\012' | sed -e '/^-[[^D]]/d' -e '/-D[[^_]]/d' -e 's/-D_/ -D_/' | tr '\012' ' ' | sed -e 's/\\\\X/\\\\ /g'`
	    break
	  fi
	done
	if test -z "$TCL_LIBS"; then
	  AC_MSG_RESULT(<not found>)
	  AC_MSG_CHECKING(for Tcl library by myself)
	  tcllib=`echo $tclinc | sed s/include/lib/g`
	  for ext in .so .a ; do
	    for ver in "" $tclver ; do
	      for try in $tcllib ; do
		trylib=tcl$ver$ext
		if test -f $try/lib$trylib ; then
		  AC_MSG_RESULT($try/lib$trylib)
		  TCL_LIBS="-L$try -ltcl$ver -ldl -lm"
		  if test "`(uname) 2>/dev/null`" = SunOS &&
					 uname -r | grep '^5' >/dev/null; then
		    TCL_LIBS="$TCL_LIBS -R $try"
		  fi
		  break 3
		fi
	      done
	    done
	  done
	  if test -z "$TCL_LIBS"; then
	    AC_MSG_RESULT(<not found>)
	    SKIP_TCL=YES
	  fi
	fi
	if test -z "$SKIP_TCL"; then
	  AC_DEFINE(FEAT_TCL)
	  TCL_SRC=if_tcl.c
	  TCL_OBJ=objects/if_tcl.o
	  TCL_PRO=if_tcl.pro
	  TCL_CFLAGS="-I$TCL_INC $TCL_DEFS"
	fi
      fi
    else
      AC_MSG_RESULT(too old; need Tcl version 8.0 or later)
    fi
  fi
fi
AC_SUBST(TCL_SRC)
AC_SUBST(TCL_OBJ)
AC_SUBST(TCL_PRO)
AC_SUBST(TCL_CFLAGS)
AC_SUBST(TCL_LIBS)

AC_MSG_CHECKING(--enable-rubyinterp argument)
AC_ARG_ENABLE(rubyinterp,
	[  --enable-rubyinterp     Include Ruby interpreter.], ,
	[enable_rubyinterp="no"])
AC_MSG_RESULT($enable_rubyinterp)
if test "$enable_rubyinterp" = "yes"; then
  AC_SUBST(vi_cv_path_ruby)
  AC_PATH_PROG(vi_cv_path_ruby, ruby)
  if test "X$vi_cv_path_ruby" != "X"; then
    AC_MSG_CHECKING(Ruby version)
    if $vi_cv_path_ruby -e '(VERSION rescue RUBY_VERSION) >= "1.6.0" or exit 1' >/dev/null 2>/dev/null; then
      AC_MSG_RESULT(OK)
      AC_MSG_CHECKING(Ruby header files)
      rubyhdrdir=`$vi_cv_path_ruby -r mkmf -e 'print Config::CONFIG[["archdir"]] || $hdrdir' 2>/dev/null`
      if test "X$rubyhdrdir" != "X"; then
	AC_MSG_RESULT($rubyhdrdir)
	RUBY_CFLAGS="-I$rubyhdrdir"
	rubylibs=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["LIBS"]]'`
	if test "X$rubylibs" != "X"; then
	  RUBY_LIBS="$rubylibs"
	fi
	librubyarg=`$vi_cv_path_ruby -r rbconfig -e 'print Config.expand(Config::CONFIG[["LIBRUBYARG"]])'`
	if test -f "$rubyhdrdir/$librubyarg"; then
	  librubyarg="$rubyhdrdir/$librubyarg"
	else
	  rubylibdir=`$vi_cv_path_ruby -r rbconfig -e 'print Config.expand(Config::CONFIG[["libdir"]])'`
	  if test -f "$rubylibdir/$librubyarg"; then
	    librubyarg="$rubylibdir/$librubyarg"
	  elif test "$librubyarg" = "libruby.a"; then
	    dnl required on Mac OS 10.3 where libruby.a doesn't exist
	    librubyarg="-lruby"
	  else
	    librubyarg=`$vi_cv_path_ruby -r rbconfig -e "print '$librubyarg'.gsub(/-L\./, %'-L#{Config.expand(Config::CONFIG[\"libdir\"])}')"`
	  fi
	fi

	if test "X$librubyarg" != "X"; then
	  RUBY_LIBS="$librubyarg $RUBY_LIBS"
	fi
	rubyldflags=`$vi_cv_path_ruby -r rbconfig -e 'print Config::CONFIG[["LDFLAGS"]]'`
	if test "X$rubyldflags" != "X"; then
	  LDFLAGS="$rubyldflags $LDFLAGS"
	fi
	RUBY_SRC="if_ruby.c"
	RUBY_OBJ="objects/if_ruby.o"
	RUBY_PRO="if_ruby.pro"
	AC_DEFINE(FEAT_RUBY)
      else
	AC_MSG_RESULT(not found, disabling Ruby)
      fi
    else
      AC_MSG_RESULT(too old; need Ruby version 1.6.0 or later)
    fi
  fi
fi
AC_SUBST(RUBY_SRC)
AC_SUBST(RUBY_OBJ)
AC_SUBST(RUBY_PRO)
AC_SUBST(RUBY_CFLAGS)
AC_SUBST(RUBY_LIBS)

AC_MSG_CHECKING(--enable-cscope argument)
AC_ARG_ENABLE(cscope,
	[  --enable-cscope         Include cscope interface.], ,
	[enable_cscope="no"])
AC_MSG_RESULT($enable_cscope)
if test "$enable_cscope" = "yes"; then
  AC_DEFINE(FEAT_CSCOPE)
fi

AC_MSG_CHECKING(--enable-workshop argument)
AC_ARG_ENABLE(workshop,
	[  --enable-workshop       Include Sun Visual Workshop support.], ,
	[enable_workshop="no"])
AC_MSG_RESULT($enable_workshop)
if test "$enable_workshop" = "yes"; then
  AC_DEFINE(FEAT_SUN_WORKSHOP)
  WORKSHOP_SRC="workshop.c integration.c"
  AC_SUBST(WORKSHOP_SRC)
  WORKSHOP_OBJ="objects/workshop.o objects/integration.o"
  AC_SUBST(WORKSHOP_OBJ)
  if test "${enable_gui-xxx}" = xxx; then
    enable_gui=motif
  fi
fi

AC_MSG_CHECKING(--disable-netbeans argument)
AC_ARG_ENABLE(netbeans,
	[  --disable-netbeans      Disable NetBeans integration support.],
	, [enable_netbeans="yes"])
if test "$enable_netbeans" = "yes"; then
  AC_MSG_RESULT(no)
  dnl On Solaris we need the socket and nsl library.
  AC_CHECK_LIB(socket, socket)
  AC_CHECK_LIB(nsl, gethostbyname)
  AC_MSG_CHECKING(whether compiling netbeans integration is possible)
  AC_TRY_LINK([
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
	/* Check bitfields */
	struct nbbuf {
	unsigned int  initDone:1;
	ushort signmaplen;
	};
	    ], [
		/* Check creating a socket. */
		struct sockaddr_in server;
		(void)socket(AF_INET, SOCK_STREAM, 0);
		(void)htons(100);
		(void)gethostbyname("microsoft.com");
		if (errno == ECONNREFUSED)
		  (void)connect(1, (struct sockaddr *)&server, sizeof(server));
	    ],
	AC_MSG_RESULT(yes),
	AC_MSG_RESULT(no); enable_netbeans="no")
else
  AC_MSG_RESULT(yes)
fi
if test "$enable_netbeans" = "yes"; then
  AC_DEFINE(FEAT_NETBEANS_INTG)
  NETBEANS_SRC="netbeans.c"
  AC_SUBST(NETBEANS_SRC)
  NETBEANS_OBJ="objects/netbeans.o"
  AC_SUBST(NETBEANS_OBJ)
fi

AC_MSG_CHECKING(--enable-sniff argument)
AC_ARG_ENABLE(sniff,
	[  --enable-sniff          Include Sniff interface.], ,
	[enable_sniff="no"])
AC_MSG_RESULT($enable_sniff)
if test "$enable_sniff" = "yes"; then
  AC_DEFINE(FEAT_SNIFF)
  SNIFF_SRC="if_sniff.c"
  AC_SUBST(SNIFF_SRC)
  SNIFF_OBJ="objects/if_sniff.o"
  AC_SUBST(SNIFF_OBJ)
fi

AC_MSG_CHECKING(--enable-multibyte argument)
AC_ARG_ENABLE(multibyte,
	[  --enable-multibyte      Include multibyte editing support.], ,
	[enable_multibyte="no"])
AC_MSG_RESULT($enable_multibyte)
if test "$enable_multibyte" = "yes"; then
  AC_DEFINE(FEAT_MBYTE)
fi

AC_MSG_CHECKING(--enable-hangulinput argument)
AC_ARG_ENABLE(hangulinput,
	[  --enable-hangulinput    Include Hangul input support.], ,
	[enable_hangulinput="no"])
AC_MSG_RESULT($enable_hangulinput)

AC_MSG_CHECKING(--enable-xim argument)
AC_ARG_ENABLE(xim,
	[  --enable-xim            Include XIM input support.],
	AC_MSG_RESULT($enable_xim),
	[enable_xim="auto"; AC_MSG_RESULT(defaulting to auto)])
dnl defining FEAT_XIM is delayed, so that it can be disabled for older GTK

AC_MSG_CHECKING(--enable-fontset argument)
AC_ARG_ENABLE(fontset,
	[  --enable-fontset        Include X fontset output support.], ,
	[enable_fontset="no"])
AC_MSG_RESULT($enable_fontset)
dnl defining FEAT_XFONTSET is delayed, so that it can be disabled for no GUI

test -z "$with_x" && with_x=yes
test "${enable_gui-yes}" != no -a "x$MACOSX" != "xyes" -a "x$QNX" != "xyes" && with_x=yes
if test "$with_x" = no; then
  AC_MSG_RESULT(defaulting to: don't HAVE_X11)
else
  dnl Do this check early, so that its failure can override user requests.

  AC_PATH_PROG(xmkmfpath, xmkmf)

  AC_PATH_XTRA

  dnl On OS390Unix the X libraries are DLLs. To use them the code must
  dnl be compiled with a special option.
  dnl Also add SM, ICE and Xmu to X_EXTRA_LIBS.
  if test "$OS390Unix" = "yes"; then
    CFLAGS="$CFLAGS -W c,dll"
    LDFLAGS="$LDFLAGS -W l,dll"
    X_EXTRA_LIBS="$X_EXTRA_LIBS -lSM -lICE -lXmu"
  fi

  dnl On my HPUX system the X include dir is found, but the lib dir not.
  dnl This is a desparate try to fix this.

  if test -d "$x_includes" && test ! -d "$x_libraries"; then
    x_libraries=`echo "$x_includes" | sed s/include/lib/`
    AC_MSG_RESULT(Corrected X libraries to $x_libraries)
    X_LIBS="$X_LIBS -L$x_libraries"
    if test "`(uname) 2>/dev/null`" = SunOS &&
					 uname -r | grep '^5' >/dev/null; then
      X_LIBS="$X_LIBS -R $x_libraries"
    fi
  fi

  if test -d "$x_libraries" && test ! -d "$x_includes"; then
    x_includes=`echo "$x_libraries" | sed s/lib/include/`
    AC_MSG_RESULT(Corrected X includes to $x_includes)
    X_CFLAGS="$X_CFLAGS -I$x_includes"
  fi

  dnl Remove "-I/usr/include " from X_CFLAGS, should not be needed.
  X_CFLAGS="`echo $X_CFLAGS\  | sed 's%-I/usr/include %%'`"
  dnl Remove "-L/usr/lib " from X_LIBS, should not be needed.
  X_LIBS="`echo $X_LIBS\  | sed 's%-L/usr/lib %%'`"
  dnl Same for "-R/usr/lib ".
  X_LIBS="`echo $X_LIBS\  | sed -e 's%-R/usr/lib %%' -e 's%-R /usr/lib %%'`"


  dnl Check if the X11 header files are correctly installed. On some systems
  dnl Xlib.h includes files that don't exist
  AC_MSG_CHECKING(if X11 header files can be found)
  cflags_save=$CFLAGS
  CFLAGS="$CFLAGS $X_CFLAGS"
  AC_TRY_COMPILE([#include <X11/Xlib.h>], ,
	AC_MSG_RESULT(yes),
	AC_MSG_RESULT(no); no_x=yes)
  CFLAGS=$cflags_save

  if test "${no_x-no}" = yes; then
    with_x=no
  else
    AC_DEFINE(HAVE_X11)
    X_LIB="-lXt -lX11";
    AC_SUBST(X_LIB)

    ac_save_LDFLAGS="$LDFLAGS"
    LDFLAGS="-L$x_libraries $LDFLAGS"

    dnl Check for -lXdmcp (needed on SunOS 4.1.4)
    dnl For HP-UX 10.20 it must be before -lSM -lICE
    AC_CHECK_LIB(Xdmcp, _XdmcpAuthDoIt, [X_EXTRA_LIBS="$X_EXTRA_LIBS -lXdmcp"],,
		[-lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS -lXdmcp])

    dnl Some systems need -lnsl -lsocket when testing for ICE.
    dnl The check above doesn't do this, try here (again).  Also needed to get
    dnl them after Xdmcp.  link.sh will remove them when not needed.
    dnl Check for other function than above to avoid the cached value
    AC_CHECK_LIB(ICE, IceOpenConnection,
		  [X_EXTRA_LIBS="$X_EXTRA_LIBS -lSM -lICE"],, [$X_EXTRA_LIBS])

    dnl Check for -lXpm (needed for some versions of Motif)
    LDFLAGS="$X_LIBS $ac_save_LDFLAGS"
    AC_CHECK_LIB(Xpm, XpmCreatePixmapFromData, [X_PRE_LIBS="$X_PRE_LIBS -lXpm"],,
		[-lXt $X_PRE_LIBS -lXpm -lX11 $X_EXTRA_LIBS])

    dnl Check that the X11 header files don't use implicit declarations
    AC_MSG_CHECKING(if X11 header files implicitly declare return values)
    cflags_save=$CFLAGS
    CFLAGS="$CFLAGS $X_CFLAGS -Werror"
    AC_TRY_COMPILE([#include <X11/Xlib.h>], ,
	AC_MSG_RESULT(no),
	CFLAGS="$CFLAGS -Wno-implicit-int"
	AC_TRY_COMPILE([#include <X11/Xlib.h>], ,
	    AC_MSG_RESULT(yes); cflags_save="$cflags_save -Wno-implicit-int",
	    AC_MSG_RESULT(test failed)
	)
    )
    CFLAGS=$cflags_save

    LDFLAGS="$ac_save_LDFLAGS"

  fi
fi

test "x$with_x" = xno -a "x$MACOSX" != "xyes" -a "x$QNX" != "xyes" && enable_gui=no

AC_MSG_CHECKING(--enable-gui argument)
AC_ARG_ENABLE(gui,
 [  --enable-gui[=OPTS]     X11 GUI [default=auto] [OPTS=auto/no/gtk/gtk2/gnome/gnome2/motif/athena/neXtaw/photon/carbon]], , enable_gui="auto")

dnl Canonicalize the --enable-gui= argument so that it can be easily compared.
dnl Do not use character classes for portability with old tools.
enable_gui_canon=`echo "_$enable_gui" | \
	sed 's/[[ _+-]]//g;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`

dnl Skip everything by default.
SKIP_GTK=YES
SKIP_GTK2=YES
SKIP_GNOME=YES
SKIP_MOTIF=YES
SKIP_ATHENA=YES
SKIP_NEXTAW=YES
SKIP_PHOTON=YES
SKIP_CARBON=YES
GUITYPE=NONE

if test "x$QNX" = "xyes" -a "x$with_x" = "xno" ; then
  SKIP_PHOTON=
  case "$enable_gui_canon" in
    no)		AC_MSG_RESULT(no GUI support)
		SKIP_PHOTON=YES ;;
    yes|"")	AC_MSG_RESULT(yes - automatic GUI support) ;;
    auto)	AC_MSG_RESULT(auto - automatic GUI support) ;;
    photon)	AC_MSG_RESULT(Photon GUI support) ;;
    *)		AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported])
		SKIP_PHOTON=YES ;;
  esac

elif test "x$MACOSX" = "xyes" -a "x$with_x" = "xno" ; then
  SKIP_CARBON=
  case "$enable_gui_canon" in
    no)		AC_MSG_RESULT(no GUI support)
		SKIP_CARBON=YES ;;
    yes|"")	AC_MSG_RESULT(yes - automatic GUI support) ;;
    auto)	AC_MSG_RESULT(auto - automatic GUI support) ;;
    carbon)	AC_MSG_RESULT(Carbon GUI support) ;;
    *)		AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported])
		SKIP_CARBON=YES ;;
  esac

else

  case "$enable_gui_canon" in
    no|none)	AC_MSG_RESULT(no GUI support) ;;
    yes|""|auto)	AC_MSG_RESULT(yes/auto - automatic GUI support)
		SKIP_GTK=
		SKIP_GTK2=
		SKIP_GNOME=
		SKIP_MOTIF=
		SKIP_ATHENA=
		SKIP_NEXTAW=
		SKIP_CARBON=;;
    gtk)	AC_MSG_RESULT(GTK+ 1.x GUI support)
		SKIP_GTK=;;
    gtk2)	AC_MSG_RESULT(GTK+ 2.x GUI support)
		SKIP_GTK=
		SKIP_GTK2=;;
    gnome)	AC_MSG_RESULT(GNOME 1.x GUI support)
		SKIP_GNOME=
		SKIP_GTK=;;
    gnome2)	AC_MSG_RESULT(GNOME 2.x GUI support)
		SKIP_GNOME=
		SKIP_GTK=
		SKIP_GTK2=;;
    motif)	AC_MSG_RESULT(Motif GUI support)
		SKIP_MOTIF=;;
    athena)	AC_MSG_RESULT(Athena GUI support)
		SKIP_ATHENA=;;
    nextaw)	AC_MSG_RESULT(neXtaw GUI support)
		SKIP_NEXTAW=;;
    *)		AC_MSG_RESULT([Sorry, $enable_gui GUI is not supported]) ;;
  esac

fi

if test "x$SKIP_GTK" != "xYES" -a "$enable_gui_canon" != "gtk" -a "$enable_gui_canon" != "gtk2"; then
  AC_MSG_CHECKING(whether or not to look for GTK)
  AC_ARG_ENABLE(gtk-check,
	[  --enable-gtk-check      If auto-select GUI, check for GTK [default=yes]],
	, enable_gtk_check="yes")
  AC_MSG_RESULT($enable_gtk_check)
  if test "x$enable_gtk_check" = "xno"; then
    SKIP_GTK=YES
    SKIP_GNOME=YES
  fi
fi

if test "x$SKIP_GTK2" != "xYES" -a "$enable_gui_canon" != "gtk2" \
				-a "$enable_gui_canon" != "gnome2"; then
  AC_MSG_CHECKING(whether or not to look for GTK+ 2)
  AC_ARG_ENABLE(gtk2-check,
	[  --enable-gtk2-check     If GTK GUI, check for GTK+ 2 [default=yes]],
	, enable_gtk2_check="yes")
  AC_MSG_RESULT($enable_gtk2_check)
  if test "x$enable_gtk2_check" = "xno"; then
    SKIP_GTK2=YES
  fi
fi

if test "x$SKIP_GNOME" != "xYES" -a "$enable_gui_canon" != "gnome" \
				 -a "$enable_gui_canon" != "gnome2"; then
  AC_MSG_CHECKING(whether or not to look for GNOME)
  AC_ARG_ENABLE(gnome-check,
	[  --enable-gnome-check    If GTK GUI, check for GNOME [default=no]],
	, enable_gnome_check="no")
  AC_MSG_RESULT($enable_gnome_check)
  if test "x$enable_gnome_check" = "xno"; then
    SKIP_GNOME=YES
  fi
fi

if test "x$SKIP_MOTIF" != "xYES" -a "$enable_gui_canon" != "motif"; then
  AC_MSG_CHECKING(whether or not to look for Motif)
  AC_ARG_ENABLE(motif-check,
	[  --enable-motif-check    If auto-select GUI, check for Motif [default=yes]],
	, enable_motif_check="yes")
  AC_MSG_RESULT($enable_motif_check)
  if test "x$enable_motif_check" = "xno"; then
    SKIP_MOTIF=YES
  fi
fi

if test "x$SKIP_ATHENA" != "xYES" -a "$enable_gui_canon" != "athena"; then
  AC_MSG_CHECKING(whether or not to look for Athena)
  AC_ARG_ENABLE(athena-check,
	[  --enable-athena-check   If auto-select GUI, check for Athena [default=yes]],
	, enable_athena_check="yes")
  AC_MSG_RESULT($enable_athena_check)
  if test "x$enable_athena_check" = "xno"; then
    SKIP_ATHENA=YES
  fi
fi

if test "x$SKIP_NEXTAW" != "xYES" -a "$enable_gui_canon" != "nextaw"; then
  AC_MSG_CHECKING(whether or not to look for neXtaw)
  AC_ARG_ENABLE(nextaw-check,
	[  --enable-nextaw-check   If auto-select GUI, check for neXtaw [default=yes]],
	, enable_nextaw_check="yes")
  AC_MSG_RESULT($enable_nextaw_check);
  if test "x$enable_nextaw_check" = "xno"; then
    SKIP_NEXTAW=YES
  fi
fi

if test "x$SKIP_CARBON" != "xYES" -a "$enable_gui_canon" != "carbon"; then
  AC_MSG_CHECKING(whether or not to look for Carbon)
  AC_ARG_ENABLE(carbon-check,
	[  --enable-carbon-check   If auto-select GUI, check for Carbon [default=yes]],
	, enable_carbon_check="yes")
  AC_MSG_RESULT($enable_carbon_check);
  if test "x$enable_carbon_check" = "xno"; then
    SKIP_CARBON=YES
  fi
fi


if test "x$MACOSX" = "xyes" -a -z "$SKIP_CARBON" -a "x$CARBON" = "xyes"; then
  AC_MSG_CHECKING(for Carbon GUI)
  dnl already did this
  AC_MSG_RESULT(yes);
  GUITYPE=CARBONGUI
  if test "$VIMNAME" = "vim"; then
    VIMNAME=Vim
  fi
  dnl skip everything else
  SKIP_GTK=YES;
  SKIP_GTK2=YES;
  SKIP_GNOME=YES;
  SKIP_MOTIF=YES;
  SKIP_ATHENA=YES;
  SKIP_NEXTAW=YES;
  SKIP_PHOTON=YES;
  SKIP_CARBON=YES
fi

dnl
dnl Get the cflags and libraries from the gtk-config script
dnl

dnl define an autoconf function to check for a specified version of GTK, and
dnl try to compile/link a GTK program.  this gets used once for GTK 1.1.16.
dnl
dnl AM_PATH_GTK([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
dnl Test for GTK, and define GTK_CFLAGS, GTK_LIBDIR and GTK_LIBS
dnl
AC_DEFUN(AM_PATH_GTK,
[
  if test "X$GTK_CONFIG" != "Xno" -o "X$PKG_CONFIG" != "Xno"; then
  {
    min_gtk_version=ifelse([$1], ,0.99.7,$1)
    AC_MSG_CHECKING(for GTK - version >= $min_gtk_version)
    no_gtk=""
    if (test "X$SKIP_GTK2" != "XYES" -a "X$PKG_CONFIG" != "Xno") \
	  && $PKG_CONFIG --exists gtk+-2.0; then
    {
      dnl We should be using PKG_CHECK_MODULES() instead of this hack.
      dnl But I guess the dependency on pkgconfig.m4 is not wanted or
      dnl something like that.
      GTK_CFLAGS=`$PKG_CONFIG --cflags gtk+-2.0`
      GTK_LIBDIR=`$PKG_CONFIG --libs-only-L gtk+-2.0`
      GTK_LIBS=`$PKG_CONFIG --libs gtk+-2.0`
      gtk_major_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
	     sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
      gtk_minor_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
	     sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
      gtk_micro_version=`$PKG_CONFIG --modversion gtk+-2.0 | \
	     sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
    }
    elif test "X$GTK_CONFIG" != "Xno"; then
    {
      GTK_CFLAGS=`$GTK_CONFIG $gtk_config_args --cflags`
      GTK_LIBDIR=
      GTK_LIBS=`$GTK_CONFIG $gtk_config_args --libs`
      gtk_major_version=`$GTK_CONFIG $gtk_config_args --version | \
	     sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
      gtk_minor_version=`$GTK_CONFIG $gtk_config_args --version | \
	     sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
      gtk_micro_version=`$GTK_CONFIG $gtk_config_args --version | \
	     sed 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
    }
    else
      no_gtk=yes
    fi

    if test "x$enable_gtktest" = "xyes" -a "x$no_gtk" = "x"; then
    {
      ac_save_CFLAGS="$CFLAGS"
      ac_save_LIBS="$LIBS"
      CFLAGS="$CFLAGS $GTK_CFLAGS"
      LIBS="$LIBS $GTK_LIBS"

      dnl
      dnl Now check if the installed GTK is sufficiently new. (Also sanity
      dnl checks the results of gtk-config to some extent
      dnl
      rm -f conf.gtktest
      AC_TRY_RUN([
#include <gtk/gtk.h>
#include <stdio.h>

int
main ()
{
int major, minor, micro;
char *tmp_version;

system ("touch conf.gtktest");

/* HP/UX 9 (%@#!) writes to sscanf strings */
tmp_version = g_strdup("$min_gtk_version");
if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
   printf("%s, bad version string\n", "$min_gtk_version");
   exit(1);
 }

if ((gtk_major_version > major) ||
    ((gtk_major_version == major) && (gtk_minor_version > minor)) ||
    ((gtk_major_version == major) && (gtk_minor_version == minor) &&
				     (gtk_micro_version >= micro)))
{
    return 0;
}
return 1;
}
],, no_gtk=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
      CFLAGS="$ac_save_CFLAGS"
      LIBS="$ac_save_LIBS"
    }
    fi
    if test "x$no_gtk" = x ; then
      if test "x$enable_gtktest" = "xyes"; then
	AC_MSG_RESULT(yes; found version $gtk_major_version.$gtk_minor_version.$gtk_micro_version)
      else
	AC_MSG_RESULT(found version $gtk_major_version.$gtk_minor_version.$gtk_micro_version)
      fi
      ifelse([$2], , :, [$2])
    else
    {
      AC_MSG_RESULT(no)
      GTK_CFLAGS=""
      GTK_LIBS=""
      ifelse([$3], , :, [$3])
    }
    fi
  }
  else
    GTK_CFLAGS=""
    GTK_LIBS=""
    ifelse([$3], , :, [$3])
  fi
  AC_SUBST(GTK_CFLAGS)
  AC_SUBST(GTK_LIBS)
  rm -f conf.gtktest
])

dnl ---------------------------------------------------------------------------
dnl gnome
dnl ---------------------------------------------------------------------------
AC_DEFUN([GNOME_INIT_HOOK],
[
  AC_SUBST(GNOME_LIBS)
  AC_SUBST(GNOME_LIBDIR)
  AC_SUBST(GNOME_INCLUDEDIR)

  AC_ARG_WITH(gnome-includes,
    [  --with-gnome-includes=DIR Specify location of GNOME headers],
    [CFLAGS="$CFLAGS -I$withval"]
  )

  AC_ARG_WITH(gnome-libs,
    [  --with-gnome-libs=DIR   Specify location of GNOME libs],
    [LDFLAGS="$LDFLAGS -L$withval" gnome_prefix=$withval]
  )

  AC_ARG_WITH(gnome,
    [  --with-gnome            Specify prefix for GNOME files],
    if test x$withval = xyes; then
      want_gnome=yes
      ifelse([$1], [], :, [$1])
    else
      if test "x$withval" = xno; then
	want_gnome=no
      else
	want_gnome=yes
	LDFLAGS="$LDFLAGS -L$withval/lib"
	CFLAGS="$CFLAGS -I$withval/include"
	gnome_prefix=$withval/lib
      fi
    fi,
    want_gnome=yes)

  if test "x$want_gnome" = xyes -a "0$gtk_major_version" -ge 2; then
  {
    AC_MSG_CHECKING(for libgnomeui-2.0)
    if $PKG_CONFIG --exists libgnomeui-2.0; then
      AC_MSG_RESULT(yes)
      GNOME_LIBS=`$PKG_CONFIG --libs-only-l libgnomeui-2.0`
      GNOME_LIBDIR=`$PKG_CONFIG --libs-only-L libgnomeui-2.0`
      GNOME_INCLUDEDIR=`$PKG_CONFIG --cflags libgnomeui-2.0`
     
      dnl On FreeBSD we need -pthread but pkg-config doesn't include it.
      dnl This might not be the right way but it works for me...
      AC_MSG_CHECKING(for FreeBSD)
      if test "`(uname) 2>/dev/null`" = FreeBSD; then
	AC_MSG_RESULT(yes, adding -pthread)
        GNOME_INCLUDEDIR="$GNOME_INCLUDEDIR -D_THREAD_SAFE"
	GNOME_LIBS="$GNOME_LIBS -pthread"
      else
	AC_MSG_RESULT(no)
      fi
      $1
    else
      AC_MSG_RESULT(not found)
      if test "x$2" = xfail; then
	AC_MSG_ERROR(Could not find libgnomeui-2.0 via pkg-config)
      fi
    fi
  }
  elif test "x$want_gnome" = xyes; then
  {
    AC_PATH_PROG(GNOME_CONFIG,gnome-config,no)
    if test "$GNOME_CONFIG" = "no"; then
      no_gnome_config="yes"
    else
      AC_MSG_CHECKING(if $GNOME_CONFIG works)
      if $GNOME_CONFIG --libs-only-l gnome >/dev/null 2>&1; then
	AC_MSG_RESULT(yes)
	GNOME_LIBS="`$GNOME_CONFIG --libs-only-l gnome gnomeui`"
	GNOME_LIBDIR="`$GNOME_CONFIG --libs-only-L gnorba gnomeui`"
	GNOME_INCLUDEDIR="`$GNOME_CONFIG --cflags gnorba gnomeui`"
	$1
      else
	AC_MSG_RESULT(no)
	no_gnome_config="yes"
      fi
    fi

    if test x$exec_prefix = xNONE; then
      if test x$prefix = xNONE; then
	gnome_prefix=$ac_default_prefix/lib
      else
	gnome_prefix=$prefix/lib
      fi
    else
      gnome_prefix=`eval echo \`echo $libdir\``
    fi

    if test "$no_gnome_config" = "yes"; then
      AC_MSG_CHECKING(for gnomeConf.sh file in $gnome_prefix)
      if test -f $gnome_prefix/gnomeConf.sh; then
	AC_MSG_RESULT(found)
	echo "loading gnome configuration from" \
	  "$gnome_prefix/gnomeConf.sh"
	. $gnome_prefix/gnomeConf.sh
	$1
      else
	AC_MSG_RESULT(not found)
	if test x$2 = xfail; then
	  AC_MSG_ERROR(Could not find the gnomeConf.sh file that is generated by gnome-libs install)
	fi
      fi
    fi
  }
  fi
])

AC_DEFUN([GNOME_INIT],[
	GNOME_INIT_HOOK([],fail)
])


dnl ---------------------------------------------------------------------------
dnl Check for GTK.  First checks for gtk-config, cause it needs that to get the
dnl correct compiler flags.  Then checks for GTK 1.1.16.  If that fails, then
dnl it checks for 1.0.6.  If both fail, then continue on for Motif as before...
dnl ---------------------------------------------------------------------------
if test -z "$SKIP_GTK"; then

  AC_MSG_CHECKING(--with-gtk-prefix argument)
  AC_ARG_WITH(gtk-prefix,[  --with-gtk-prefix=PFX   Prefix where GTK is installed (optional)],
	gtk_config_prefix="$withval"; AC_MSG_RESULT($gtk_config_prefix),
	gtk_config_prefix=""; AC_MSG_RESULT(no))

  AC_MSG_CHECKING(--with-gtk-exec-prefix argument)
  AC_ARG_WITH(gtk-exec-prefix,[  --with-gtk-exec-prefix=PFX Exec prefix where GTK is installed (optional)],
	gtk_config_exec_prefix="$withval"; AC_MSG_RESULT($gtk_config_prefix),
	gtk_config_exec_prefix=""; AC_MSG_RESULT(no))

  AC_MSG_CHECKING(--disable-gtktest argument)
  AC_ARG_ENABLE(gtktest, [  --disable-gtktest       Do not try to compile and run a test GTK program],
	, enable_gtktest=yes)
  if test "x$enable_gtktest" = "xyes" ; then
    AC_MSG_RESULT(gtk test enabled)
  else
    AC_MSG_RESULT(gtk test disabled)
  fi

  if test "x$gtk_config_prefix" != "x" ; then
    gtk_config_args="$gtk_config_args --prefix=$gtk_config_prefix"
    GTK_CONFIG=$gtk_config_prefix/bin/gtk-config
  fi
  if test "x$gtk_config_exec_prefix" != "x" ; then
    gtk_config_args="$gtk_config_args --exec-prefix=$gtk_config_exec_prefix"
    GTK_CONFIG=$gtk_config_exec_prefix/bin/gtk-config
  fi
  if test "X$GTK_CONFIG" = "X"; then
    AC_PATH_PROG(GTK_CONFIG, gtk-config, no)
    if test "X$GTK_CONFIG" = "Xno"; then
      dnl Some distributions call it gtk12-config, annoying!
      AC_PATH_PROG(GTK12_CONFIG, gtk12-config, no)
      GTK_CONFIG="$GTK12_CONFIG"
    fi
  else
    AC_MSG_RESULT(Using GTK configuration program $GTK_CONFIG)
  fi
  if test "X$PKG_CONFIG" = "X"; then
    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
  fi

  if test "x$GTK_CONFIG:$PKG_CONFIG" != "xno:no"; then
    dnl First try finding version 2.2.0 or later.  The 2.0.x series has
    dnl problems (bold fonts, --remote doesn't work).
    if test "X$SKIP_GTK2" != "XYES"; then
      AM_PATH_GTK(2.2.0,
		  [GUI_LIB_LOC="$GTK_LIBDIR"
		   GTK_LIBNAME="$GTK_LIBS"
		  GUI_INC_LOC="$GTK_CFLAGS"], )
      if test "x$GTK_CFLAGS" != "x"; then
	SKIP_ATHENA=YES
	SKIP_NEXTAW=YES
	SKIP_MOTIF=YES
	GUITYPE=GTK
	AC_SUBST(GTK_LIBNAME)
      fi
    fi

    dnl If there is no 2.2.0 or later try the 1.x.x series.  We require at
    dnl least GTK 1.1.16.  1.0.6 doesn't work.  1.1.1 to 1.1.15
    dnl were test versions.
    if test "x$GUITYPE" != "xGTK"; then
      SKIP_GTK2=YES
      AM_PATH_GTK(1.1.16,
		  [GTK_LIBNAME="$GTK_LIBS"
		  GUI_INC_LOC="$GTK_CFLAGS"], )
      if test "x$GTK_CFLAGS" != "x"; then
	SKIP_ATHENA=YES
	SKIP_NEXTAW=YES
	SKIP_MOTIF=YES
	GUITYPE=GTK
	AC_SUBST(GTK_LIBNAME)
      fi
    fi
  fi
  dnl Give a warning if GTK is older than 1.2.3
  if test "x$GUITYPE" = "xGTK"; then
    if test "$gtk_major_version" = 1 -a "0$gtk_minor_version" -lt 2 \
	 -o "$gtk_major_version" = 1 -a "$gtk_minor_version" = 2 -a "0$gtk_micro_version" -lt 3; then
      AC_MSG_RESULT(this GTK version is old; version 1.2.3 or later is recommended)
    else
    {
      if test "0$gtk_major_version" -ge 2; then
	AC_DEFINE(HAVE_GTK2)
	if test "$gtk_minor_version" = 1 -a "0$gtk_micro_version" -ge 1 \
		|| test "0$gtk_minor_version" -ge 2 \
		|| test "0$gtk_major_version" -gt 2; then
	  AC_DEFINE(HAVE_GTK_MULTIHEAD)
	fi
      fi
      dnl
      dnl if GTK exists, and it's not the 1.0.x series, then check for GNOME.
      dnl
      if test -z "$SKIP_GNOME"; then
      {
	GNOME_INIT_HOOK([have_gnome=yes])
	if test x$have_gnome = xyes ; then
	  AC_DEFINE(FEAT_GUI_GNOME)
	  GUI_INC_LOC="$GUI_INC_LOC $GNOME_INCLUDEDIR"
	  GTK_LIBNAME="$GTK_LIBNAME $GNOME_LIBDIR $GNOME_LIBS"
	fi
      }
      fi
    }
    fi
  fi
fi

dnl Check for Motif include files location.
dnl The LAST one found is used, this makes the highest version to be used,
dnl e.g. when Motif1.2 and Motif2.0 are both present.

if test -z "$SKIP_MOTIF"; then
  gui_XXX="/usr/XXX/Motif* /usr/Motif*/XXX /usr/XXX /usr/shlib /usr/X11*/XXX /usr/XXX/X11* /usr/dt/XXX /local/Motif*/XXX /local/XXX/Motif* /usr/local/Motif*/XXX /usr/local/XXX/Motif* /usr/local/XXX /usr/local/X11*/XXX /usr/local/LessTif/Motif*/XXX $MOTIFHOME/XXX"
  dnl Remove "-I" from before $GUI_INC_LOC if it's there
  GUI_INC_LOC="`echo $GUI_INC_LOC|sed 's%-I%%g'`"

  AC_MSG_CHECKING(for location of Motif GUI includes)
  gui_includes="`echo $x_includes|sed 's%/[^/][^/]*$%%'` `echo "$gui_XXX" | sed s/XXX/include/g` $GUI_INC_LOC"
  GUI_INC_LOC=
  for try in $gui_includes; do
    if test -f "$try/Xm/Xm.h"; then
      GUI_INC_LOC=$try
    fi
  done
  if test -n "$GUI_INC_LOC"; then
    if test "$GUI_INC_LOC" = /usr/include; then
      GUI_INC_LOC=
      AC_MSG_RESULT(in default path)
    else
      AC_MSG_RESULT($GUI_INC_LOC)
    fi
  else
    AC_MSG_RESULT(<not found>)
    SKIP_MOTIF=YES
  fi
fi

dnl Check for Motif library files location.  In the same order as the include
dnl files, to avoid a mixup if several versions are present

if test -z "$SKIP_MOTIF"; then
  AC_MSG_CHECKING(--with-motif-lib argument)
  AC_ARG_WITH(motif-lib,
  [  --with-motif-lib=STRING   Library for Motif ],
  [ MOTIF_LIBNAME="${withval}" ] )

  if test -n "$MOTIF_LIBNAME"; then
    AC_MSG_RESULT($MOTIF_LIBNAME)
    GUI_LIB_LOC=
  else
    AC_MSG_RESULT(no)

    dnl Remove "-L" from before $GUI_LIB_LOC if it's there
    GUI_LIB_LOC="`echo $GUI_LIB_LOC|sed 's%-L%%g'`"

    AC_MSG_CHECKING(for location of Motif GUI libs)
    gui_libs="`echo $x_libraries|sed 's%/[^/][^/]*$%%'` `echo "$gui_XXX" | sed s/XXX/lib/g` `echo "$GUI_INC_LOC" | sed s/include/lib/` $GUI_LIB_LOC"
    GUI_LIB_LOC=
    for try in $gui_libs; do
      for libtry in "$try"/libXm.a "$try"/libXm.so* "$try"/libXm.sl "$try"/libXm.dylib; do
	if test -f "$libtry"; then
	  GUI_LIB_LOC=$try
	fi
      done
    done
    if test -n "$GUI_LIB_LOC"; then
      dnl Remove /usr/lib, it causes trouble on some systems
      if test "$GUI_LIB_LOC" = /usr/lib; then
	GUI_LIB_LOC=
	AC_MSG_RESULT(in default path)
      else
	if test -n "$GUI_LIB_LOC"; then
	  AC_MSG_RESULT($GUI_LIB_LOC)
	  if test "`(uname) 2>/dev/null`" = SunOS &&
					 uname -r | grep '^5' >/dev/null; then
	    GUI_LIB_LOC="$GUI_LIB_LOC -R $GUI_LIB_LOC"
	  fi
	fi
      fi
      MOTIF_LIBNAME=-lXm
    else
      AC_MSG_RESULT(<not found>)
      SKIP_MOTIF=YES
    fi
  fi
fi

if test -z "$SKIP_MOTIF"; then
  SKIP_ATHENA=YES
  SKIP_NEXTAW=YES
  GUITYPE=MOTIF
  AC_SUBST(MOTIF_LIBNAME)
fi

dnl Check if the Athena files can be found

GUI_X_LIBS=

if test -z "$SKIP_ATHENA"; then
  AC_MSG_CHECKING(if Athena header files can be found)
  cflags_save=$CFLAGS
  CFLAGS="$CFLAGS $X_CFLAGS"
  AC_TRY_COMPILE([
#include <X11/Intrinsic.h>
#include <X11/Xaw/Paned.h>], ,
	AC_MSG_RESULT(yes),
	AC_MSG_RESULT(no); SKIP_ATHENA=YES )
  CFLAGS=$cflags_save
fi

if test -z "$SKIP_ATHENA"; then
  GUITYPE=ATHENA
fi

if test -z "$SKIP_NEXTAW"; then
  AC_MSG_CHECKING(if neXtaw header files can be found)
  cflags_save=$CFLAGS
  CFLAGS="$CFLAGS $X_CFLAGS"
  AC_TRY_COMPILE([
#include <X11/Intrinsic.h>
#include <X11/neXtaw/Paned.h>], ,
	AC_MSG_RESULT(yes),
	AC_MSG_RESULT(no); SKIP_NEXTAW=YES )
  CFLAGS=$cflags_save
fi

if test -z "$SKIP_NEXTAW"; then
  GUITYPE=NEXTAW
fi

if test -z "$SKIP_ATHENA" -o -z "$SKIP_NEXTAW" -o -z "$SKIP_MOTIF"; then
  dnl Prepend -I and -L to $GUI_INC_LOC and $GUI_LIB_LOC if not empty
  dnl Avoid adding it when it twice
  if test -n "$GUI_INC_LOC"; then
    GUI_INC_LOC=-I"`echo $GUI_INC_LOC|sed 's%-I%%'`"
  fi
  if test -n "$GUI_LIB_LOC"; then
    GUI_LIB_LOC=-L"`echo $GUI_LIB_LOC|sed 's%-L%%'`"
  fi

  dnl Check for -lXext and then for -lXmu
  ldflags_save=$LDFLAGS
  LDFLAGS="$X_LIBS $LDFLAGS"
  AC_CHECK_LIB(Xext, XShapeQueryExtension, [GUI_X_LIBS="-lXext"],,
		[-lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
  dnl For Solaris we need -lw and -ldl before linking with -lXmu works.
  AC_CHECK_LIB(w, wslen, [X_EXTRA_LIBS="$X_EXTRA_LIBS -lw"],,
		[$GUI_X_LIBS -lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
  AC_CHECK_LIB(dl, dlsym, [X_EXTRA_LIBS="$X_EXTRA_LIBS -ldl"],,
		[$GUI_X_LIBS -lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
  AC_CHECK_LIB(Xmu, XmuCreateStippledPixmap, [GUI_X_LIBS="-lXmu $GUI_X_LIBS"],,
		[$GUI_X_LIBS -lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
  if test -z "$SKIP_MOTIF"; then
    AC_CHECK_LIB(Xp, XpEndJob, [GUI_X_LIBS="-lXp $GUI_X_LIBS"],,
		[$GUI_X_LIBS -lXm -lXt $X_PRE_LIBS -lX11 $X_EXTRA_LIBS])
  fi
  LDFLAGS=$ldflags_save

  dnl Execute xmkmf to figure out if -DNARROWPROTO is needed.
  AC_MSG_CHECKING(for extra X11 defines)
  NARROW_PROTO=
  rm -fr conftestdir
  if mkdir conftestdir; then
    cd conftestdir
    cat > Imakefile <<'EOF'
acfindx:
	@echo 'NARROW_PROTO="${PROTO_DEFINES}"'
EOF
    if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
      eval `${MAKE-make} acfindx 2>/dev/null | grep -v make`
    fi
    cd ..
    rm -fr conftestdir
  fi
  if test -z "$NARROW_PROTO"; then
    AC_MSG_RESULT(no)
  else
    AC_MSG_RESULT($NARROW_PROTO)
  fi
  AC_SUBST(NARROW_PROTO)
fi

dnl Look for XSMP support - but don't necessarily restrict it to X11 GUIs
dnl use the X11 include path
if test "$enable_xsmp" = "yes"; then
  cppflags_save=$CPPFLAGS
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
  AC_CHECK_HEADERS(X11/SM/SMlib.h)
  CPPFLAGS=$cppflags_save
fi


if test -z "$SKIP_ATHENA" -o -z "$SKIP_NEXTAW" -o -z "$SKIP_MOTIF" -o -z "$SKIP_GTK"; then
  dnl Check for X11/xpm.h and X11/Sunkeysym.h with the GUI include path
  cppflags_save=$CPPFLAGS
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
  AC_CHECK_HEADERS(X11/xpm.h X11/Sunkeysym.h)

  dnl automatically disable XIM when XIMtext isn't in X11/Xlib.h
  if test ! "$enable_xim" = "no"; then
    AC_MSG_CHECKING(for XIMText in X11/Xlib.h)
    AC_EGREP_CPP(XIMText, [#include <X11/Xlib.h>],
		  AC_MSG_RESULT(yes),
		  AC_MSG_RESULT(no; xim has been disabled); enable_xim = "no")
  fi
  CPPFLAGS=$cppflags_save

  dnl automatically enable XIM when hangul input isn't enabled
  if test "$enable_xim" = "auto" -a "$enable_hangulinput" != "yes" \
		-a "x$GUITYPE" != "xNONE" ; then
    AC_MSG_RESULT(X GUI selected; xim has been enabled)
    enable_xim="yes"
  fi
fi

if test -z "$SKIP_ATHENA" -o -z "$SKIP_NEXTAW" -o -z "$SKIP_MOTIF"; then
  cppflags_save=$CPPFLAGS
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
dnl Xmu/Editres.h may exist but can only be used after including Intrinsic.h
  AC_MSG_CHECKING([for X11/Xmu/Editres.h])
  AC_TRY_COMPILE([
#include <X11/Intrinsic.h>
#include <X11/Xmu/Editres.h>],
		      [int i; i = 0;],
	      AC_MSG_RESULT(yes)
		      AC_DEFINE(HAVE_X11_XMU_EDITRES_H),
	      AC_MSG_RESULT(no))
  CPPFLAGS=$cppflags_save
fi

dnl Only use the Xm directory when compiling Motif, don't use it for Athena
if test -z "$SKIP_MOTIF"; then
  cppflags_save=$CPPFLAGS
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
  AC_CHECK_HEADERS(Xm/Xm.h Xm/XpmP.h Xm/JoinSideT.h Xm/TraitP.h Xm/Manager.h \
		   Xm/UnhighlightT.h)

  if test $ac_cv_header_Xm_XpmP_h = yes; then
    dnl Solaris uses XpmAttributes_21, very annoying.
    AC_MSG_CHECKING([for XpmAttributes_21 in Xm/XpmP.h])
    AC_TRY_COMPILE([#include <Xm/XpmP.h>], [XpmAttributes_21 attr;],
	AC_MSG_RESULT(yes); AC_DEFINE(XPMATTRIBUTES_TYPE, XpmAttributes_21),
	AC_MSG_RESULT(no); AC_DEFINE(XPMATTRIBUTES_TYPE, XpmAttributes)
	)
  else
    AC_DEFINE(XPMATTRIBUTES_TYPE, XpmAttributes_21)
  fi
  CPPFLAGS=$cppflags_save
fi

if test "x$GUITYPE" = "xNONE" -a "$enable_xim" = "yes"; then
  AC_MSG_RESULT(no GUI selected; xim has been disabled)
  enable_xim="no"
fi
if test "x$GUITYPE" = "xNONE" -a "$enable_fontset" = "yes"; then
  AC_MSG_RESULT(no GUI selected; fontset has been disabled)
  enable_fontset="no"
fi
if test "x$GUITYPE:$enable_fontset" = "xGTK:yes" -a "0$gtk_major_version" -ge 2; then
  AC_MSG_RESULT(GTK+ 2 GUI selected; fontset has been disabled)
  enable_fontset="no"
fi

if test -z "$SKIP_PHOTON"; then
  GUITYPE=PHOTONGUI
fi

AC_SUBST(GUI_INC_LOC)
AC_SUBST(GUI_LIB_LOC)
AC_SUBST(GUITYPE)
AC_SUBST(GUI_X_LIBS)

if test "$enable_workshop" = "yes" -a -n "$SKIP_MOTIF"; then
  AC_MSG_ERROR([cannot use workshop without Motif])
fi

dnl defining FEAT_XIM and FEAT_XFONTSET is delayed, so that they can be disabled
if test "$enable_xim" = "yes"; then
  AC_DEFINE(FEAT_XIM)
fi
if test "$enable_fontset" = "yes"; then
  AC_DEFINE(FEAT_XFONTSET)
fi


dnl ---------------------------------------------------------------------------
dnl end of GUI-checking
dnl ---------------------------------------------------------------------------


dnl Only really enable hangul input when GUI and XFONTSET are available
if test "$enable_hangulinput" = "yes"; then
  if test "x$GUITYPE" = "xNONE"; then
    AC_MSG_RESULT(no GUI selected; hangul input has been disabled)
    enable_hangulinput=no
  else
    AC_DEFINE(FEAT_HANGULIN)
    HANGULIN_SRC=hangulin.c
    AC_SUBST(HANGULIN_SRC)
    HANGULIN_OBJ=objects/hangulin.o
    AC_SUBST(HANGULIN_OBJ)
  fi
fi

dnl Checks for libraries and include files.

AC_MSG_CHECKING(quality of toupper)
AC_TRY_RUN([#include <ctype.h>
main() { exit(toupper('A') == 'A' && tolower('z') == 'z'); }],
	AC_DEFINE(BROKEN_TOUPPER) AC_MSG_RESULT(bad),
	AC_MSG_RESULT(good), AC_MSG_ERROR(failed to compile test program))

AC_MSG_CHECKING(whether __DATE__ and __TIME__ work)
AC_TRY_COMPILE(, [printf("(" __DATE__ " " __TIME__ ")");],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_DATE_TIME),
	AC_MSG_RESULT(no))

dnl Checks for header files.
AC_CHECK_HEADER(elf.h, HAS_ELF=1)
dnl AC_CHECK_HEADER(dwarf.h, SVR4=1)
if test "$HAS_ELF" = 1; then
  AC_CHECK_LIB(elf, main)
fi

AC_HEADER_DIRENT

dnl check for standard headers, we don't use this in Vim but other stuff
dnl in autoconf needs it
AC_HEADER_STDC
AC_HEADER_SYS_WAIT

dnl If sys/wait.h is not found it might still exist but not be POSIX
dnl compliant. In that case we define HAVE_UNION_WAIT (for NeXT)
if test $ac_cv_header_sys_wait_h = no; then
  AC_MSG_CHECKING([for sys/wait.h that defines union wait])
  AC_TRY_COMPILE([#include <sys/wait.h>],
			[union wait xx, yy; xx = yy],
		AC_MSG_RESULT(yes)
			AC_DEFINE(HAVE_SYS_WAIT_H)
			AC_DEFINE(HAVE_UNION_WAIT),
		AC_MSG_RESULT(no))
fi

AC_CHECK_HEADERS(stdarg.h stdlib.h string.h sys/select.h sys/utsname.h \
	termcap.h fcntl.h sgtty.h sys/ioctl.h sys/time.h termio.h \
	iconv.h langinfo.h unistd.h stropts.h errno.h \
	sys/resource.h sys/systeminfo.h locale.h \
	sys/stream.h sys/ptem.h termios.h libc.h sys/statfs.h \
	poll.h sys/poll.h pwd.h utime.h sys/param.h libintl.h \
	libgen.h util/debug.h util/msg18n.h frame.h \
	sys/acl.h sys/access.h sys/sysctl.h sys/sysinfo.h wchar.h wctype.h)

dnl pthread_np.h may exist but can only be used after including pthread.h
AC_MSG_CHECKING([for pthread_np.h])
AC_TRY_COMPILE([
#include <pthread.h>
#include <pthread_np.h>],
		      [int i; i = 0;],
	      AC_MSG_RESULT(yes)
		      AC_DEFINE(HAVE_PTHREAD_NP_H),
	      AC_MSG_RESULT(no))

AC_CHECK_HEADERS(strings.h)
if test "x$MACOSX" = "xyes"; then
  dnl The strings.h file on OS/X contains a warning and nothing useful.
  AC_DEFINE(NO_STRINGS_WITH_STRING_H)
else

dnl Check if strings.h and string.h can both be included when defined.
AC_MSG_CHECKING([if strings.h can be included after string.h])
cppflags_save=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $X_CFLAGS"
AC_TRY_COMPILE([
#if defined(_AIX) && !defined(_AIX51) && !defined(_NO_PROTO)
# define _NO_PROTO	/* like in os_unix.h, causes conflict for AIX (Winn) */
			/* but don't do it on AIX 5.1 (Uribarri) */
#endif
#ifdef HAVE_XM_XM_H
# include <Xm/Xm.h>	/* This breaks it for HP-UX 11 (Squassabia) */
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#if defined(HAVE_STRINGS_H)
# include <strings.h>
#endif
		], [int i; i = 0;],
		AC_MSG_RESULT(yes),
		AC_DEFINE(NO_STRINGS_WITH_STRING_H)
		AC_MSG_RESULT(no))
CPPFLAGS=$cppflags_save
fi

dnl Checks for typedefs, structures, and compiler characteristics.
AC_PROG_GCC_TRADITIONAL
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T
AC_HEADER_TIME
AC_CHECK_TYPE(ino_t, long)
AC_CHECK_TYPE(dev_t, unsigned)

AC_MSG_CHECKING(for rlim_t)
if eval "test \"`echo '$''{'ac_cv_type_rlim_t'+set}'`\" = set"; then
  AC_MSG_RESULT([(cached) $ac_cv_type_rlim_t])
else
  AC_EGREP_CPP(dnl
changequote(<<,>>)dnl
<<(^|[^a-zA-Z_0-9])rlim_t[^a-zA-Z_0-9]>>dnl
changequote([,]),
  [
#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
	  ], ac_cv_type_rlim_t=yes, ac_cv_type_rlim_t=no)
	  AC_MSG_RESULT($ac_cv_type_rlim_t)
fi
if test $ac_cv_type_rlim_t = no; then
  cat >> confdefs.h <<\EOF
#define rlim_t unsigned long
EOF
fi

AC_MSG_CHECKING(for stack_t)
if eval "test \"`echo '$''{'ac_cv_type_stack_t'+set}'`\" = set"; then
  AC_MSG_RESULT([(cached) $ac_cv_type_stack_t])
else
  AC_EGREP_CPP(stack_t,
  [
#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
#include <signal.h>
	  ], ac_cv_type_stack_t=yes, ac_cv_type_stack_t=no)
	  AC_MSG_RESULT($ac_cv_type_stack_t)
fi
if test $ac_cv_type_stack_t = no; then
  cat >> confdefs.h <<\EOF
#define stack_t struct sigaltstack
EOF
fi

dnl BSDI uses ss_base while others use ss_sp for the stack pointer.
AC_MSG_CHECKING(whether stack_t has an ss_base field)
AC_TRY_COMPILE([
#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
#include <signal.h>
#include "confdefs.h"
			], [stack_t sigstk; sigstk.ss_base = 0; ],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SS_BASE),
	AC_MSG_RESULT(no))

olibs="$LIBS"
AC_MSG_CHECKING(--with-tlib argument)
AC_ARG_WITH(tlib, [  --with-tlib=library     terminal library to be used ],)
if test -n "$with_tlib"; then
  AC_MSG_RESULT($with_tlib)
  LIBS="$LIBS -l$with_tlib"
  AC_MSG_CHECKING(for linking with $with_tlib library)
  AC_TRY_LINK([], [], AC_MSG_RESULT(OK), AC_MSG_ERROR(FAILED))
  dnl Need to check for tgetent() below.
  olibs="$LIBS"
else
  AC_MSG_RESULT([empty: automatic terminal library selection])
  dnl  On HP-UX 10.10 termcap or termlib should be used instead of
  dnl  curses, because curses is much slower.
  dnl  Newer versions of ncurses are preferred over anything.
  dnl  Older versions of ncurses have bugs, get a new one!
  dnl  Digital Unix (OSF1) should use curses (Ronald Schild).
  case "`uname -s 2>/dev/null`" in
	OSF1)	tlibs="ncurses curses termlib termcap";;
	*)	tlibs="ncurses termlib termcap curses";;
  esac
  for libname in $tlibs; do
    AC_CHECK_LIB(${libname}, tgetent,,)
    if test "x$olibs" != "x$LIBS"; then
      dnl It's possible that a library is found but it doesn't work
      dnl e.g., shared library that cannot be found
      dnl compile and run a test program to be sure
      AC_TRY_RUN([
#ifdef HAVE_TERMCAP_H
# include <termcap.h>
#endif
main() {char *s; s=(char *)tgoto("%p1%d", 0, 1); exit(0); }],
			  res="OK", res="FAIL", res="FAIL")
      if test "$res" = "OK"; then
	break
      fi
      AC_MSG_RESULT($libname library is not usable)
      LIBS="$olibs"
    fi
  done
  if test "x$olibs" = "x$LIBS"; then
    AC_MSG_RESULT(no terminal library found)
  fi
fi

if test "x$olibs" = "x$LIBS"; then
  AC_MSG_CHECKING([for tgetent()])
  AC_TRY_LINK([],
      [char s[10000]; int res = tgetent(s, "thisterminaldoesnotexist");],
	AC_MSG_RESULT(yes),
	AC_MSG_ERROR([NOT FOUND!
      You need to install a terminal library; for example ncurses.
      Or specify the name of the library with --with-tlib.]))
fi

AC_MSG_CHECKING(whether we talk terminfo)
AC_TRY_RUN([
#ifdef HAVE_TERMCAP_H
# include <termcap.h>
#endif
main()
{char *s; s=(char *)tgoto("%p1%d", 0, 1); exit(!strcmp(s==0 ? "" : s, "1")); }],
	  AC_MSG_RESULT([no -- we are in termcap land]),
	  AC_MSG_RESULT([yes -- terminfo spoken here]); AC_DEFINE(TERMINFO),
	  AC_MSG_ERROR(failed to compile test program.))

if test "x$olibs" != "x$LIBS"; then
  AC_MSG_CHECKING(what tgetent() returns for an unknown terminal)
  AC_TRY_RUN([
#ifdef HAVE_TERMCAP_H
# include <termcap.h>
#endif
main()
{char s[10000]; int res = tgetent(s, "thisterminaldoesnotexist"); exit(res != 0); }],
	  AC_MSG_RESULT(zero); AC_DEFINE(TGETENT_ZERO_ERR, 0),
	  AC_MSG_RESULT(non-zero),
	  AC_MSG_ERROR(failed to compile test program.))
fi

AC_MSG_CHECKING(whether termcap.h contains ospeed)
AC_TRY_LINK([
#ifdef HAVE_TERMCAP_H
# include <termcap.h>
#endif
			], [ospeed = 20000],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_OSPEED),
	[AC_MSG_RESULT(no)
	AC_MSG_CHECKING(whether ospeed can be extern)
	AC_TRY_LINK([
#ifdef HAVE_TERMCAP_H
# include <termcap.h>
#endif
extern short ospeed;
			], [ospeed = 20000],
		AC_MSG_RESULT(yes); AC_DEFINE(OSPEED_EXTERN),
		AC_MSG_RESULT(no))]
	)

AC_MSG_CHECKING([whether termcap.h contains UP, BC and PC])
AC_TRY_LINK([
#ifdef HAVE_TERMCAP_H
# include <termcap.h>
#endif
			], [if (UP == 0 && BC == 0) PC = 1],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_UP_BC_PC),
	[AC_MSG_RESULT(no)
	AC_MSG_CHECKING([whether UP, BC and PC can be extern])
	AC_TRY_LINK([
#ifdef HAVE_TERMCAP_H
# include <termcap.h>
#endif
extern char *UP, *BC, PC;
			], [if (UP == 0 && BC == 0) PC = 1],
		AC_MSG_RESULT(yes); AC_DEFINE(UP_BC_PC_EXTERN),
		AC_MSG_RESULT(no))]
	)

AC_MSG_CHECKING(whether tputs() uses outfuntype)
AC_TRY_COMPILE([
#ifdef HAVE_TERMCAP_H
# include <termcap.h>
#endif
			], [extern int xx(); tputs("test", 1, (outfuntype)xx)],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_OUTFUNTYPE),
	AC_MSG_RESULT(no))

dnl On some SCO machines sys/select redefines struct timeval
AC_MSG_CHECKING([whether sys/select.h and sys/time.h may both be included])
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/time.h>
#include <sys/select.h>], ,
	  AC_MSG_RESULT(yes)
			AC_DEFINE(SYS_SELECT_WITH_SYS_TIME),
	  AC_MSG_RESULT(no))

dnl AC_DECL_SYS_SIGLIST

dnl Checks for pty.c (copied from screen) ==========================
AC_MSG_CHECKING(for /dev/ptc)
if test -r /dev/ptc; then
  AC_DEFINE(HAVE_DEV_PTC)
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi

AC_MSG_CHECKING(for SVR4 ptys)
if test -c /dev/ptmx ; then
  AC_TRY_LINK([], [ptsname(0);grantpt(0);unlockpt(0);],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SVR4_PTYS),
	AC_MSG_RESULT(no))
else
  AC_MSG_RESULT(no)
fi

AC_MSG_CHECKING(for ptyranges)
if test -d /dev/ptym ; then
  pdir='/dev/ptym'
else
  pdir='/dev'
fi
dnl SCO uses ptyp%d
AC_EGREP_CPP(yes,
[#ifdef M_UNIX
   yes;
#endif
	], ptys=`echo /dev/ptyp??`, ptys=`echo $pdir/pty??`)
dnl if test -c /dev/ptyp19; then
dnl ptys=`echo /dev/ptyp??`
dnl else
dnl ptys=`echo $pdir/pty??`
dnl fi
if test "$ptys" != "$pdir/pty??" ; then
  p0=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\).$/\1/g' | sort -u | tr -d '\012'`
  p1=`echo $ptys | tr ' ' '\012' | sed -e 's/^.*\(.\)$/\1/g'  | sort -u | tr -d '\012'`
  AC_DEFINE_UNQUOTED(PTYRANGE0,"$p0")
  AC_DEFINE_UNQUOTED(PTYRANGE1,"$p1")
  AC_MSG_RESULT([$p0 / $p1])
else
  AC_MSG_RESULT([don't know])
fi

dnl    ****  pty mode/group handling ****
dnl
dnl support provided by Luke Mewburn <lm@rmit.edu.au>, 931222
AC_MSG_CHECKING(default tty permissions/group)
rm -f conftest_grp
AC_TRY_RUN([
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
main()
{
  struct stat sb;
  char *x,*ttyname();
  int om, m;
  FILE *fp;

  if (!(x = ttyname(0))) exit(1);
  if (stat(x, &sb)) exit(1);
  om = sb.st_mode;
  if (om & 002) exit(0);
  m = system("mesg y");
  if (m == -1 || m == 127) exit(1);
  if (stat(x, &sb)) exit(1);
  m = sb.st_mode;
  if (chmod(x, om)) exit(1);
  if (m & 002) exit(0);
  if (sb.st_gid == getgid()) exit(1);
  if (!(fp=fopen("conftest_grp", "w")))
    exit(1);
  fprintf(fp, "%d\n", sb.st_gid);
  fclose(fp);
  exit(0);
}
],[
    if test -f conftest_grp; then
	ptygrp=`cat conftest_grp`
	AC_MSG_RESULT([pty mode: 0620, group: $ptygrp])
	AC_DEFINE(PTYMODE, 0620)
	AC_DEFINE_UNQUOTED(PTYGROUP,$ptygrp)
    else
	AC_MSG_RESULT([ptys are world accessable])
    fi
],
    AC_MSG_RESULT([can't determine - assume ptys are world accessable]),
    AC_MSG_ERROR(failed to compile test program))
rm -f conftest_grp

dnl Checks for library functions. ===================================

AC_TYPE_SIGNAL

dnl find out what to use at the end of a signal function
if test $ac_cv_type_signal = void; then
  AC_DEFINE(SIGRETURN, [return])
else
  AC_DEFINE(SIGRETURN, [return 0])
fi

dnl check if struct sigcontext is defined (used for SGI only)
AC_MSG_CHECKING(for struct sigcontext)
AC_TRY_COMPILE([
#include <signal.h>
test_sig()
{
    struct sigcontext *scont;
    scont = (struct sigcontext *)0;
    return 1;
} ], ,
	  AC_MSG_RESULT(yes)
		AC_DEFINE(HAVE_SIGCONTEXT),
	  AC_MSG_RESULT(no))

dnl tricky stuff: try to find out if getcwd() is implemented with
dnl system("sh -c pwd")
AC_MSG_CHECKING(getcwd implementation)
AC_TRY_RUN([
char *dagger[] = { "IFS=pwd", 0 };
main()
{
  char buffer[500];
  extern char **environ;
  environ = dagger;
  return getcwd(buffer, 500) ? 0 : 1;
}],
	AC_MSG_RESULT(it is usable),
	AC_MSG_RESULT(it stinks)
		AC_DEFINE(BAD_GETCWD),
	AC_MSG_ERROR(failed to compile test program))

dnl Check for functions in one big call, to reduce the size of configure
AC_CHECK_FUNCS(bcmp fchdir fchown fseeko fsync ftello getcwd getpseudotty \
	getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
	memset nanosleep opendir putenv qsort readlink select setenv \
	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
	sigvec strcasecmp strerror strftime stricmp strncasecmp \
	strnicmp strpbrk strtol tgetent towlower towupper iswupper \
	usleep utime utimes)

dnl fstatfs() can take 2 to 4 arguments, try to use st_blksize if possible
AC_MSG_CHECKING(for st_blksize)
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/stat.h>],
[	struct stat st;
	int n;

	stat("/", &st);
	n = (int)st.st_blksize;],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_ST_BLKSIZE),
	AC_MSG_RESULT(no))

AC_MSG_CHECKING(whether stat() ignores a trailing slash)
AC_TRY_RUN(
[#include <sys/types.h>
#include <sys/stat.h>
main() {struct stat st;  exit(stat("configure/", &st) != 0); }],
	AC_MSG_RESULT(yes); AC_DEFINE(STAT_IGNORES_SLASH),
	AC_MSG_RESULT(no), AC_MSG_ERROR(failed to compile test program))

dnl Link with iconv for charset translation, if not found without library.
dnl check for iconv() requires including iconv.h
dnl Add "-liconv" when possible; Solaris has iconv but use GNU iconv when it
dnl has been installed.
AC_MSG_CHECKING(for iconv_open())
save_LIBS="$LIBS"
LIBS="$LIBS -liconv"
AC_TRY_LINK([
#ifdef HAVE_ICONV_H
# include <iconv.h>
#endif
    ], [iconv_open("fr", "to");],
    AC_MSG_RESULT(yes; with -liconv); AC_DEFINE(HAVE_ICONV),
    LIBS="$save_LIBS"
    AC_TRY_LINK([
#ifdef HAVE_ICONV_H
# include <iconv.h>
#endif
	], [iconv_open("fr", "to");],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_ICONV),
	AC_MSG_RESULT(no)))


AC_MSG_CHECKING(for nl_langinfo(CODESET))
AC_TRY_LINK([
#ifdef HAVE_LANGINFO_H
# include <langinfo.h>
#endif
], [char *cs = nl_langinfo(CODESET);],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_NL_LANGINFO_CODESET),
	AC_MSG_RESULT(no))

dnl Link with -lposix1e for ACL stuff; if not found, try -lacl for SGI
dnl when -lacl works, also try to use -lattr (required for Debian).
AC_MSG_CHECKING(--disable-acl argument)
AC_ARG_ENABLE(acl,
	[  --disable-acl           Don't check for ACL support.],
	, [enable_acl="yes"])
if test "$enable_acl" = "yes"; then
AC_MSG_RESULT(no)
AC_CHECK_LIB(posix1e, acl_get_file, [LIBS="$LIBS -lposix1e"],
	AC_CHECK_LIB(acl, acl_get_file, [LIBS="$LIBS -lacl"
		  AC_CHECK_LIB(attr, fgetxattr, LIBS="$LIBS -lattr",,)],,),)

AC_MSG_CHECKING(for POSIX ACL support)
AC_TRY_LINK([
#include <sys/types.h>
#ifdef HAVE_SYS_ACL_H
# include <sys/acl.h>
#endif
acl_t acl;], [acl = acl_get_file("foo", ACL_TYPE_ACCESS);
	acl_set_file("foo", ACL_TYPE_ACCESS, acl);
	acl_free(acl);],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_POSIX_ACL),
	AC_MSG_RESULT(no))

AC_MSG_CHECKING(for Solaris ACL support)
AC_TRY_LINK([
#ifdef HAVE_SYS_ACL_H
# include <sys/acl.h>
#endif], [acl("foo", GETACLCNT, 0, NULL);
	],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SOLARIS_ACL),
	AC_MSG_RESULT(no))

AC_MSG_CHECKING(for AIX ACL support)
AC_TRY_LINK([
#ifdef HAVE_SYS_ACL_H
# include <sys/acl.h>
#endif
#ifdef HAVE_SYS_ACCESS_H
# include <sys/access.h>
#endif
#define _ALL_SOURCE

#include <sys/stat.h>

int aclsize;
struct acl *aclent;], [aclsize = sizeof(struct acl);
	aclent = (void *)malloc(aclsize);
	statacl("foo", STX_NORMAL, aclent, aclsize);
	],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_AIX_ACL),
	AC_MSG_RESULT(no))
else
  AC_MSG_RESULT(yes)
fi

AC_MSG_CHECKING(--disable-gpm argument)
AC_ARG_ENABLE(gpm,
	[  --disable-gpm           Don't use gpm (Linux mouse daemon).], ,
	[enable_gpm="yes"])

if test "$enable_gpm" = "yes"; then
  AC_MSG_RESULT(no)
  dnl Checking if gpm support can be compiled
  AC_CACHE_CHECK([for gpm], vi_cv_have_gpm,
	[olibs="$LIBS" ; LIBS="-lgpm"]
	AC_TRY_LINK(
	    [#include <gpm.h>
	    #include <linux/keyboard.h>],
	    [Gpm_GetLibVersion(NULL);],
	    dnl Configure defines HAVE_GPM, if it is defined feature.h defines
	    dnl FEAT_MOUSE_GPM if mouse support is included
	    [vi_cv_have_gpm=yes],
	    [vi_cv_have_gpm=no])
	[LIBS="$olibs"]
    )
  if test $vi_cv_have_gpm = yes; then
    LIBS="$LIBS -lgpm"
    AC_DEFINE(HAVE_GPM)
  fi
else
  AC_MSG_RESULT(yes)
fi

dnl rename needs to be checked separately to work on Nextstep with cc
AC_MSG_CHECKING(for rename)
AC_TRY_LINK([#include <stdio.h>], [rename("this", "that")],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_RENAME),
	AC_MSG_RESULT(no))

dnl sysctl() may exist but not the arguments we use
AC_MSG_CHECKING(for sysctl)
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/sysctl.h>],
[	int mib[2], r;
	size_t len;

	mib[0] = CTL_HW;
	mib[1] = HW_USERMEM;
	len = sizeof(r);
	(void)sysctl(mib, 2, &r, &len, (void *)0, (size_t)0);
	],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCTL),
	AC_MSG_RESULT(not usable))

dnl sysinfo() may exist but not be Linux compatible
AC_MSG_CHECKING(for sysinfo)
AC_TRY_COMPILE(
[#include <sys/types.h>
#include <sys/sysinfo.h>],
[	struct sysinfo sinfo;
	int t;

	(void)sysinfo(&sinfo);
	t = sinfo.totalram;
	],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSINFO),
	AC_MSG_RESULT(not usable))

dnl sysconf() may exist but not support what we want to use
AC_MSG_CHECKING(for sysconf)
AC_TRY_COMPILE(
[#include <unistd.h>],
[	(void)sysconf(_SC_PAGESIZE);
	(void)sysconf(_SC_PHYS_PAGES);
	],
	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCONF),
	AC_MSG_RESULT(not usable))

dnl Our own version of AC_CHECK_SIZEOF(int); fixes a bug when sizeof() can't
dnl be printed with "%d", and avoids a warning for cross-compiling.

AC_MSG_CHECKING(size of int)
AC_CACHE_VAL(ac_cv_sizeof_int,
	[AC_TRY_RUN([#include <stdio.h>
		main()
		{
		  FILE *f=fopen("conftestval", "w");
		  if (!f) exit(1);
		  fprintf(f, "%d\n", (int)sizeof(int));
		  exit(0);
		}],
	    ac_cv_sizeof_int=`cat conftestval`,
	    ac_cv_sizeof_int=0,
	    AC_MSG_ERROR(failed to compile test program))])
AC_MSG_RESULT($ac_cv_sizeof_int)
AC_DEFINE_UNQUOTED(SIZEOF_INT, $ac_cv_sizeof_int)

AC_MSG_CHECKING(whether memmove/bcopy/memcpy handle overlaps)
[bcopy_test_prog='
main() {
  char buf[10];
  strcpy(buf, "abcdefghi");
  mch_memmove(buf, buf + 2, 3);
  if (strncmp(buf, "ababcf", 6))
    exit(1);
  strcpy(buf, "abcdefghi");
  mch_memmove(buf + 2, buf, 3);
  if (strncmp(buf, "cdedef", 6))
    exit(1);
  exit(0); /* libc version works properly.  */
}']

dnl Check for memmove() before bcopy(), makes memmove() be used when both are
dnl present, fixes problem with incompatibility between Solaris 2.4 and 2.5.

AC_TRY_RUN([#define mch_memmove(s,d,l) memmove(d,s,l) $bcopy_test_prog],
    AC_DEFINE(USEMEMMOVE) AC_MSG_RESULT(memmove does),
    AC_TRY_RUN([#define mch_memmove(s,d,l) bcopy(d,s,l) $bcopy_test_prog],
	AC_DEFINE(USEBCOPY) AC_MSG_RESULT(bcopy does),
	AC_TRY_RUN([#define mch_memmove(s,d,l) memcpy(d,s,l) $bcopy_test_prog],
	    AC_DEFINE(USEMEMCPY) AC_MSG_RESULT(memcpy does), AC_MSG_RESULT(no),
	    AC_MSG_ERROR(failed to compile test program)),
	AC_MSG_ERROR(failed to compile test program)),
    AC_MSG_ERROR(failed to compile test program))

dnl Check for multibyte locale functions
dnl Find out if _Xsetlocale() is supported by libX11.
dnl Check if X_LOCALE should be defined.

if test "$enable_multibyte" = "yes"; then
  cflags_save=$CFLAGS
  ldflags_save=$LDFLAGS
  if test -n "$x_includes" ; then
    CFLAGS="$CFLAGS -I$x_includes"
    LDFLAGS="$X_LIBS $LDFLAGS -lX11"
    AC_MSG_CHECKING(whether X_LOCALE needed)
    AC_TRY_COMPILE([#include <X11/Xlocale.h>],,
	AC_TRY_LINK_FUNC([_Xsetlocale], [AC_MSG_RESULT(yes)
		AC_DEFINE(X_LOCALE)], AC_MSG_RESULT(no)),
	AC_MSG_RESULT(no))
  fi
  CFLAGS=$cflags_save
  LDFLAGS=$ldflags_save
fi

dnl Link with xpg4, it is said to make Korean locale working
AC_CHECK_LIB(xpg4, _xpg4_setrunelocale, [LIBS="$LIBS -lxpg4"],,)

dnl Check how we can run ctags
dnl --version for Exuberant ctags (preferred)
dnl -t for typedefs (many ctags have this)
dnl -s for static functions (Elvis ctags only?)
dnl -v for variables. Dangerous, most ctags take this for 'vgrind style'.
dnl -i+m to test for older Exuberant ctags
AC_MSG_CHECKING(how to create tags)
test -f tags && mv tags tags.save
if (eval ctags --version /dev/null | grep Exuberant) < /dev/null 1>&AC_FD_CC 2>&1; then
  TAGPRG="ctags -I INIT+"
else
  (eval etags	   /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="etags"
  (eval etags -c   /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="etags -c"
  (eval ctags	   /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags"
  (eval ctags -t   /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags -t"
  (eval ctags -ts  /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags -ts"
  (eval ctags -tvs /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags -tvs"
  (eval ctags -i+m /dev/null) < /dev/null 1>&AC_FD_CC 2>&1 && TAGPRG="ctags -i+m"
fi
test -f tags.save && mv tags.save tags
AC_MSG_RESULT($TAGPRG) AC_SUBST(TAGPRG)

dnl Check how we can run man with a section number
AC_MSG_CHECKING(how to run man with a section nr)
MANDEF="man"
(eval man -s 2 read) < /dev/null > /dev/null 2>&AC_FD_CC && MANDEF="man -s"
AC_MSG_RESULT($MANDEF)
if test "$MANDEF" = "man -s"; then
  AC_DEFINE(USEMAN_S)
fi

dnl Check if gettext() is working and if it needs -lintl
AC_MSG_CHECKING(--disable-nls argument)
AC_ARG_ENABLE(nls,
	[  --disable-nls           Don't support NLS (gettext()).], ,
	[enable_nls="yes"])

if test "$enable_nls" = "yes"; then
  AC_MSG_RESULT(no)

  INSTALL_LANGS=install-languages
  AC_SUBST(INSTALL_LANGS)
  INSTALL_TOOL_LANGS=install-tool-languages
  AC_SUBST(INSTALL_TOOL_LANGS)

  AC_CHECK_PROG(MSGFMT, msgfmt, msgfmt, )
  AC_MSG_CHECKING([for NLS])
  if test -f po/Makefile; then
    have_gettext="no"
    if test -n "$MSGFMT"; then
      AC_TRY_LINK(
	[#include <libintl.h>],
	[gettext("Test");],
	AC_MSG_RESULT([gettext() works]); have_gettext="yes",
	  olibs=$LIBS
	  LIBS="$LIBS -lintl"
	  AC_TRY_LINK(
	      [#include <libintl.h>],
	      [gettext("Test");],
	      AC_MSG_RESULT([gettext() works with -lintl]); have_gettext="yes",
	      AC_MSG_RESULT([gettext() doesn't work]);
	      LIBS=$olibs))
    else
      AC_MSG_RESULT([msgfmt not found - disabled]);
    fi
    if test $have_gettext = "yes"; then
      AC_DEFINE(HAVE_GETTEXT)
      MAKEMO=yes
      AC_SUBST(MAKEMO)
      dnl this was added in GNU gettext 0.10.36
      AC_CHECK_FUNCS(bind_textdomain_codeset)
      dnl _nl_msg_cat_cntr is required for GNU gettext
      AC_MSG_CHECKING([for _nl_msg_cat_cntr])
      AC_TRY_LINK(
		[#include <libintl.h>
		extern int _nl_msg_cat_cntr;],
		[++_nl_msg_cat_cntr;],
		AC_MSG_RESULT([yes]); AC_DEFINE(HAVE_NL_MSG_CAT_CNTR),
		AC_MSG_RESULT([no]))
    fi
  else
    AC_MSG_RESULT([no "po/Makefile" - disabled]);
  fi
else
  AC_MSG_RESULT(yes)
fi

dnl Check for dynamic linking loader
AC_CHECK_HEADER(dlfcn.h, DLL=dlfcn.h, [AC_CHECK_HEADER(dl.h, DLL=dl.h)])
if test x${DLL} = xdlfcn.h; then
  AC_DEFINE(HAVE_DLFCN_H, 1, [ Define if we have dlfcn.h. ])
  AC_MSG_CHECKING([for dlopen()])
  AC_TRY_LINK(,[
		extern void* dlopen();
		dlopen();
      ],
      AC_MSG_RESULT(yes);
	      AC_DEFINE(HAVE_DLOPEN, 1, [ Define if we have dlopen() ]),
      AC_MSG_RESULT(no);
	      AC_MSG_CHECKING([for dlopen() in -ldl])
	      olibs=$LIBS
	      LIBS="$LIBS -ldl"
	      AC_TRY_LINK(,[
				extern void* dlopen();
				dlopen();
		 ],
		 AC_MSG_RESULT(yes);
			  AC_DEFINE(HAVE_DLOPEN, 1, [ Define if we have dlopen() ]),
		 AC_MSG_RESULT(no);
			  LIBS=$olibs))
  dnl ReliantUNIX has dlopen() in libc but everything else in libdl
  dnl ick :-)
  AC_MSG_CHECKING([for dlsym()])
  AC_TRY_LINK(,[
		extern void* dlsym();
		dlsym();
      ],
      AC_MSG_RESULT(yes);
	      AC_DEFINE(HAVE_DLSYM, 1, [ Define if we have dlsym() ]),
      AC_MSG_RESULT(no);
	      AC_MSG_CHECKING([for dlsym() in -ldl])
	      olibs=$LIBS
	      LIBS="$LIBS -ldl"
	      AC_TRY_LINK(,[
				extern void* dlsym();
				dlsym();
		 ],
		 AC_MSG_RESULT(yes);
			  AC_DEFINE(HAVE_DLSYM, 1, [ Define if we have dlsym() ]),
		 AC_MSG_RESULT(no);
			  LIBS=$olibs))
elif test x${DLL} = xdl.h; then
  AC_DEFINE(HAVE_DL_H, 1, [ Define if we have dl.h. ])
  AC_MSG_CHECKING([for shl_load()])
  AC_TRY_LINK(,[
		extern void* shl_load();
		shl_load();
     ],
     AC_MSG_RESULT(yes);
	  AC_DEFINE(HAVE_SHL_LOAD, 1, [ Define if we have shl_load() ]),
     AC_MSG_RESULT(no);
	  AC_MSG_CHECKING([for shl_load() in -ldld])
	  olibs=$LIBS
	  LIBS="$LIBS -ldld"
	  AC_TRY_LINK(,[
			extern void* shl_load();
			shl_load();
	     ],
	     AC_MSG_RESULT(yes);
		  AC_DEFINE(HAVE_SHL_LOAD, 1, [ Define if we have shl_load() ]),
	     AC_MSG_RESULT(no);
		  LIBS=$olibs))
fi
AC_CHECK_HEADERS(setjmp.h)

if test "x$MACOSX" = "xyes" -a -n "$PERL"; then
  dnl -ldl must come after DynaLoader.a
  if echo $LIBS | grep -e '-ldl' >/dev/null; then
    LIBS=`echo $LIBS | sed s/-ldl//`
    PERL_LIBS="$PERL_LIBS -ldl"
  fi
fi

if test "x$MACOSX" = "xyes" && test "x$CARBON" = "xyes" \
	&& test "x$GUITYPE" != "xCARBONGUI"; then
  AC_MSG_CHECKING(whether we need -framework Carbon)
  dnl check for MACOSX without Carbon GUI, but with FEAT_MBYTE
  if test "x$enable_multibyte" = "xyes" || test "x$features" == "xbig" \
	|| test "x$features" = "xhuge"; then
    LIBS="$LIBS -framework Carbon"
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no)
  fi
fi
if test "x$MACARCH" = "xboth"; then
  LDFLAGS="$LDFLAGS -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc"
fi

dnl gcc 3.1 changed the meaning of -MM.  The only solution appears to be to
dnl use "-isystem" instead of "-I" for all non-Vim include dirs.
dnl But only when making dependencies, cproto and lint don't take "-isystem".
dnl Mac gcc returns "powerpc-apple-darwin8-gcc-4.0.1 (GCC)...", need to allow
dnl the number before the version number.
AC_MSG_CHECKING(for GCC 3 or later)
DEPEND_CFLAGS_FILTER=
if test "$GCC" = yes; then
  gccmajor=`echo "$gccversion" | sed -e 's/^\([[1-9]]\)\..*$/\1/g'`
  if test "$gccmajor" -gt "2"; then
    DEPEND_CFLAGS_FILTER="| sed 's+-I */+-isystem /+g'"
  fi
fi
if test "$DEPEND_CFLAGS_FILTER" = ""; then
  AC_MSG_RESULT(no)
else
  AC_MSG_RESULT(yes)
fi
AC_SUBST(DEPEND_CFLAGS_FILTER)

dnl write output files
AC_OUTPUT(auto/config.mk:config.mk.in)

dnl vim: set sw=2 tw=78 fo+=l: