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

AC_INIT
AC_CONFIG_SRCDIR([Src/zsh.h])
AC_PREREQ([2.69])
AC_CONFIG_HEADERS([config.h])

dnl What version of zsh are we building ?
. ${srcdir}/Config/version.mk
echo "configuring for zsh $VERSION"

dnl ----------------------------------------------
dnl CHECK FOR MACHINE/VENDOR/OPERATING SYSTEM TYPE
dnl ----------------------------------------------
dnl Find out machine type, vendor, and operating system
dnl What type of host is this?
AC_CANONICAL_HOST
AC_DEFINE_UNQUOTED(MACHTYPE, "$host_cpu",
[Define to be the machine type (microprocessor class or machine model).])
AC_DEFINE_UNQUOTED(VENDOR,   "$host_vendor",
[Define to be a string corresponding the vendor of the machine.])
AC_DEFINE_UNQUOTED(OSTYPE,   "$host_os",
[Define to be the name of the operating system.])

dnl -----------------------------
dnl CHECKING COMMAND LINE OPTIONS
dnl -----------------------------
dnl Handle --program-prefix, --program-suffix, etc.
zsh_ARG_PROGRAM

dnl Handle setting of compile flags (CPPFLAGS, CFLAGS, LDFLAGS, LIBS).
zsh_COMPILE_FLAGS($CPPFLAGS, $CFLAGS, $LDFLAGS, $LIBS)

dnl Do you want to debug zsh?
ifdef([zsh-debug],[undefine([zsh-debug])])dnl
AH_TEMPLATE([DEBUG],
[Define to 1 if you want to debug zsh.])
AC_ARG_ENABLE(zsh-debug,
AS_HELP_STRING([--enable-zsh-debug],[compile with debug code and debugger symbols]),
[if test x$enableval = xyes; then
  AC_DEFINE(DEBUG)
fi])

dnl Do you want zsh memory allocation routines.
ifdef([zsh-mem],[undefine([zsh-mem])])dnl
AH_TEMPLATE([ZSH_MEM],
[Define to 1 if you want to use zsh's own memory allocation routines])
AC_ARG_ENABLE(zsh-mem,
AS_HELP_STRING([--enable-zsh-mem],[compile with zsh memory allocation routines]),
[if test x$enableval = xyes; then
  AC_DEFINE(ZSH_MEM)
fi])

dnl Do you want to debug zsh memory allocation routines.
ifdef([zsh-mem-debug],[undefine([zsh-mem-debug])])dnl
AH_TEMPLATE([ZSH_MEM_DEBUG],
[Define to 1 if you want to debug zsh memory allocation routines.])
AC_ARG_ENABLE(zsh-mem-debug,
AS_HELP_STRING([--enable-zsh-mem-debug],[debug zsh memory allocation routines]),
[if test x$enableval = xyes; then
  AC_DEFINE(ZSH_MEM_DEBUG)
fi])

dnl Do you want to print warnings when errors in memory allocation.
AH_TEMPLATE([ZSH_MEM_WARNING],
[Define to 1 if you want to turn on warnings of memory allocation errors])
ifdef([zsh-mem-warning],[undefine([zsh-mem-warning])])dnl
AC_ARG_ENABLE(zsh-mem-warning,
AS_HELP_STRING([--enable-zsh-mem-warning],[print warnings for errors in memory allocation]),
[if test x$enableval = xyes; then
  AC_DEFINE(ZSH_MEM_WARNING)
fi])

dnl Do you want to turn on error checking for free().
ifdef([zsh-secure-free],[undefine([zsh-secure-free])])dnl
AH_TEMPLATE([ZSH_SECURE_FREE],
[Define to 1 if you want to turn on memory checking for free().])
AC_ARG_ENABLE(zsh-secure-free,
AS_HELP_STRING([--enable-zsh-secure-free],[turn on error checking for free()]),
[if test x$enableval = xyes; then
  AC_DEFINE(ZSH_SECURE_FREE)
fi])

dnl Do you want to debug zsh heap allocation?
dnl Does not depend on zsh-mem.
ifdef([zsh-heap-debug],[undefine([zsh-heap-debug])])dnl
AH_TEMPLATE([ZSH_HEAP_DEBUG],
[Define to 1 if you want to turn on error checking for heap allocation.])
AC_ARG_ENABLE(zsh-heap-debug,
AS_HELP_STRING([--enable-zsh-heap-debug],[turn on error checking for heap allocation]),
[if test x$enableval = xyes; then
  AC_DEFINE(ZSH_HEAP_DEBUG)
fi])

dnl Do you want to allow Valgrind to debug heap allocation?
ifdef([zsh-valgrind],[undefine([zsh-valgrind])])dnl
AH_TEMPLATE([ZSH_VALGRIND],
[Define to 1 if you want to add code for valgrind to debug heap memory.])
AC_ARG_ENABLE(zsh-valgrind,
AS_HELP_STRING([--enable-zsh-valgrind],[turn on support for valgrind debugging of heap memory]),
[if test x$enableval = xyes;  then
  AC_DEFINE(ZSH_VALGRIND)
fi])

dnl Do you want debugging information on internal hash tables.
dnl This turns on the `hashinfo' builtin command.
ifdef([zsh-hash-debug],[undefine([zsh-hash-debug])])dnl
AH_TEMPLATE([ZSH_HASH_DEBUG],
[Define to 1 if you want to get debugging information on internal
 hash tables.  This turns on the `hashinfo' builtin.])
AC_ARG_ENABLE(zsh-hash-debug,
AS_HELP_STRING([--enable-zsh-hash-debug],[turn on debugging of internal hash tables]),
[if test x$enableval = xyes; then
  AC_DEFINE(ZSH_HASH_DEBUG)
fi])

dnl Do you want to dynamically allocate memory on the stack where possible?
ifdef([stack-allocation],[undefine([stack-allocation])])dnl
AH_TEMPLATE([USE_STACK_ALLOCATION],
[Define to 1 if you want to allocate stack memory e.g. with `alloca'.])
AC_ARG_ENABLE(stack-allocation,
AS_HELP_STRING([--enable-stack-allocation],[allocate stack memory e.g. with `alloca']),
[if test x$enableval = xyes; then
  AC_DEFINE(USE_STACK_ALLOCATION)
fi])

dnl Pathnames for global zsh scripts
ifdef([etcdir],[undefine([etcdir])])dnl
AC_ARG_ENABLE(etcdir,
AS_HELP_STRING([--enable-etcdir=DIR],[the default directory for global zsh scripts]),
[etcdir="$enableval"], [etcdir=/etc])

ifdef([zshenv],[undefine([zshenv])])dnl
AC_ARG_ENABLE(zshenv,
AS_HELP_STRING([--enable-zshenv=FILE],[the full pathname of the global zshenv script]),
[zshenv="$enableval"],
[if test "x$etcdir" = xno; then
  zshenv=no
else
  zshenv="$etcdir/zshenv"
fi])
AH_TEMPLATE([GLOBAL_ZSHENV],
[The global file to source absolutely first whenever zsh is run;
 if undefined, don't source anything.])
if test "x$zshenv" != xno; then
  AC_DEFINE_UNQUOTED(GLOBAL_ZSHENV, "$zshenv")
fi

ifdef([zshrc],[undefine([zshrc])])dnl
AC_ARG_ENABLE(zshrc,
AS_HELP_STRING([--enable-zshrc=FILE],[the full pathname of the global zshrc script]),
[zshrc="$enableval"],
[if test "x$etcdir" = xno; then
  zshrc=no
else
  zshrc="$etcdir/zshrc"
fi])
AH_TEMPLATE([GLOBAL_ZSHRC],
[The global file to source whenever zsh is run;
 if undefined, don't source anything])
if test "x$zshrc" != xno; then
  AC_DEFINE_UNQUOTED(GLOBAL_ZSHRC, "$zshrc")
fi

ifdef([zprofile],[undefine([zprofile])])dnl
AC_ARG_ENABLE(zprofile,
AS_HELP_STRING([--enable-zprofile=FILE],[the full pathname of the global zprofile script]),
[zprofile="$enableval"],
[if test "x$etcdir" = xno; then
  zprofile=no
else
  zprofile="$etcdir/zprofile"
fi])
AH_TEMPLATE([GLOBAL_ZPROFILE],
[The global file to source whenever zsh is run as a login shell,
 before zshrc is read; if undefined, don't source anything.])
if test "x$zprofile" != xno; then
  AC_DEFINE_UNQUOTED(GLOBAL_ZPROFILE, "$zprofile")
fi

ifdef([zlogin],[undefine([zlogin])])dnl
AC_ARG_ENABLE(zlogin,
AS_HELP_STRING([--enable-zlogin=FILE],[the full pathname of the global zlogin script]),
[zlogin="$enableval"],
[if test "x$etcdir" = xno; then
  zlogin=no
else
  zlogin="$etcdir/zlogin"
fi])
AH_TEMPLATE([GLOBAL_ZLOGIN],
[The global file to source whenever zsh is run as a login shell;
 if undefined, don't source anything])
if test "x$zlogin" != xno; then
  AC_DEFINE_UNQUOTED(GLOBAL_ZLOGIN, "$zlogin")
fi

ifdef([zlogout],[undefine([zlogout])])dnl
AC_ARG_ENABLE(zlogout,
AS_HELP_STRING([--enable-zlogout=FILE],[the full pathname of the global zlogout script]),
[zlogout="$enableval"],
[if test "x$etcdir" = xno; then
  zlogout=no
else
  zlogout="$etcdir/zlogout"
fi])
AH_TEMPLATE([GLOBAL_ZLOGOUT],
[The global file to source whenever zsh was run as a login shell.
 This is sourced right before exiting.  If undefined, don't source
 anything.])
if test "x$zlogout" != xno; then
  AC_DEFINE_UNQUOTED(GLOBAL_ZLOGOUT, "$zlogout")
fi

AC_SUBST(zshenv)dnl
AC_SUBST(zshrc)dnl
AC_SUBST(zprofile)dnl
AC_SUBST(zlogin)dnl
AC_SUBST(zlogout)dnl

dnl Do you want dynamically loaded binary modules.
ifdef([dynamic],[undefine([dynamic])])dnl
AC_ARG_ENABLE(dynamic,
AS_HELP_STRING([--disable-dynamic],[turn off dynamically loaded binary modules]),
[dynamic="$enableval"], [dynamic=yes])

dnl Do you want to disable restricted on r* commands
ifdef([restricted-r],[undefine([restricted-r])])dnl
AH_TEMPLATE([RESTRICTED_R],
[Undefine this if you don't want to get a restricted shell
 when zsh is exec'd with basename that starts with r.
 By default this is defined.])
AC_ARG_ENABLE(restricted-r,
AS_HELP_STRING([--disable-restricted-r],[turn off r* invocation for restricted shell]),
[if test x$enableval = xyes; then
  AC_DEFINE(RESTRICTED_R)
fi],
AC_DEFINE(RESTRICTED_R)
)

dnl Do you want to disable use of locale functions
AH_TEMPLATE([CONFIG_LOCALE],
[Undefine if you don't want local features.  By default this is defined.])
AC_ARG_ENABLE([locale],
AS_HELP_STRING([--disable-locale],[turn off locale features]),
[if test x$enableval = xyes; then
  AC_DEFINE(CONFIG_LOCALE)
fi],
AC_DEFINE(CONFIG_LOCALE)
)

ifdef([runhelpdir],[undefine([runhelpdir])])dnl
AC_ARG_ENABLE(runhelpdir,
AS_HELP_STRING([--enable-runhelpdir=DIR],[the directory in which to install run-help files]),
[if test x"$enableval" = xno; then
  runhelpdir=
else
  runhelpdir="$enableval"
fi], [runhelpdir=yes])
if test x"$runhelpdir" = xyes; then
  runhelpdir=${datadir}/${tzsh_name}/'${VERSION}'/help
fi
if test x"$runhelpdir" = x; then
  runhelp=
else
  runhelp=runhelp
fi

ifdef([fndir],[undefine([fndir])])dnl
AC_ARG_ENABLE(fndir,
AS_HELP_STRING([--enable-fndir=DIR],[the directory in which to install functions]),
dnl ${VERSION} to be determined at compile time.
[if test x$enableval = xyes; then
  fndir=${datadir}/${tzsh_name}/'${VERSION}'/functions
else
  fndir="$enableval"
fi], [fndir=${datadir}/${tzsh_name}/'${VERSION}'/functions])

ifdef([sitefndir],[undefine([sitefndir])])dnl
AC_ARG_ENABLE(site-fndir,
AS_HELP_STRING([--enable-site-fndir=DIR],[same for site functions (not version specific)]),
[if test x$enableval = xyes; then
  sitefndir=${datadir}/${tzsh_name}/site-functions
else
  sitefndir="$enableval"
fi], [sitefndir=${datadir}/${tzsh_name}/site-functions])

dnl Add /usr/local/share/zsh/site-functions if not yet present
dnl owing to $sitefndir, whether or not explicitly given.
dnl If not explicitly given, it hasn't been expanded yet.
if test X$sitefndir = X/usr/local/share/zsh/site-functions || \
   test X$sitefndir = Xno
then fixed_sitefndir=''
elif test X$prefix != X/usr/local; then
  if test X$prefix = XNONE && test X$ac_default_prefix = X/usr/local; then
    if test X$tzsh_name != Xzsh
    then fixed_sitefndir=/usr/local/share/zsh/site-functions
    else fixed_sitefndir=''
    fi
  else fixed_sitefndir=/usr/local/share/zsh/site-functions
  fi
elif test X$tzsh_name != Xzsh
then fixed_sitefndir=/usr/local/share/zsh/site-functions
else fixed_sitefndir=''
fi

ifdef([function_subdirs],[undefine([function_subdirs])])
AC_ARG_ENABLE(function-subdirs,
AS_HELP_STRING([--enable-function-subdirs],[install functions in subdirectories]))

if test "x${enable_function_subdirs}" != x &&
  test "x${enable_function_subdirs}" != xno; then
  FUNCTIONS_SUBDIRS=yes
else
  FUNCTIONS_SUBDIRS=no
fi

ifdef([additionalfpath],[undefine([additionalfpath])])dnl
AC_ARG_ENABLE(additional-fpath,
AS_HELP_STRING([--enable-additional-fpath=DIR],[add directories to default function path]),
[if test x$enableval = xyes; then
  additionalfpath=""
else
  additionalfpath="${enableval}"
fi], [additionalfpath=""])

AC_SUBST(runhelpdir)dnl
AC_SUBST(runhelp)dnl
AC_SUBST(additionalfpath)dnl
AC_SUBST(fndir)dnl
AC_SUBST(sitefndir)dnl
AC_SUBST(fixed_sitefndir)dnl
AC_SUBST(FUNCTIONS_SUBDIRS)dnl

dnl Directories for scripts such as newuser.

ifdef([scriptdir],[undefine([scriptdir])])dnl
AC_ARG_ENABLE(scriptdir,
AS_HELP_STRING([--enable-scriptdir=DIR],[the directory in which to install scripts]),
dnl ${VERSION} to be determined at compile time.
[if test x$enableval = xyes; then
  scriptdir=${datadir}/${tzsh_name}/'${VERSION}'/scripts
else
  scriptdir="$enableval"
fi], [scriptdir=${datadir}/${tzsh_name}/'${VERSION}'/scripts])

ifdef([sitescriptdir],[undefine([sitescriptdir])])dnl
AC_ARG_ENABLE(site-scriptdir,
AS_HELP_STRING([--enable-site-scriptdir=DIR],[same for site scripts (not version specific)]),
[if test x$enableval = xyes; then
  sitescriptdir=${datadir}/${tzsh_name}/scripts
else
  sitescriptdir="$enableval"
fi], [sitescriptdir=${datadir}/${tzsh_name}/scripts])

AC_SUBST(scriptdir)dnl
AC_SUBST(sitescriptdir)dnl

dnl htmldir is already handled, but if it wasn't set, use
dnl the standard zsh default.
if test x$htmldir = x'${docdir}' || test x$htmldir = x; then
  htmldir='$(datadir)/$(tzsh)/htmldoc'
fi

AH_TEMPLATE([CUSTOM_PATCHLEVEL],
[Define to a custom value for the ZSH_PATCHLEVEL parameter])
AC_ARG_ENABLE(custom-patchlevel,
AS_HELP_STRING([--enable-custom-patchlevel],[set a custom ZSH_PATCHLEVEL value]),
[if test x$enableval != x && test x$enableval != xno; then
  AC_DEFINE_UNQUOTED([CUSTOM_PATCHLEVEL], ["$enableval"])
fi])

dnl Do you want maildir support?
ifdef([maildir_support],[undefine([maildir_support])])dnl
AH_TEMPLATE([MAILDIR_SUPPORT],
[Define for Maildir support])
AC_ARG_ENABLE(maildir-support,
AS_HELP_STRING([--enable-maildir-support],[enable maildir support in MAIL and MAILPATH]),
[if test x$enableval = xyes; then
  AC_DEFINE(MAILDIR_SUPPORT)
fi])

dnl Do you want to set a maximum function depth?
ifdef([max_function_depth],[undefine([max_function_depth])])dnl
AH_TEMPLATE([MAX_FUNCTION_DEPTH],
[Define for function depth limits])
AC_ARG_ENABLE(max-function-depth,
AS_HELP_STRING([--enable-max-function-depth=MAX],[limit function depth to MAX, default 500]),
[if test x$enableval = xyes; then
  AC_DEFINE(MAX_FUNCTION_DEPTH, 500)
elif test x$enableval != xno; then
  AC_DEFINE_UNQUOTED(MAX_FUNCTION_DEPTH, $enableval)
fi],
[AC_DEFINE(MAX_FUNCTION_DEPTH, 500)]
)

ifdef([default_readnullcmd],[undefine([default_readnullcmd])])dnl
AH_TEMPLATE([DEFAULT_READNULLCMD],
[Define default pager used by readnullcmd])
AC_ARG_ENABLE(readnullcmd,
AS_HELP_STRING([--enable-readnullcmd=PAGER],[pager used when READNULLCMD is not set]),
[if test x$enableval = xyes; then
  AC_DEFINE(DEFAULT_READNULLCMD,"more")
elif test x$enableval != xno; then
  AC_DEFINE_UNQUOTED(DEFAULT_READNULLCMD,"$enableval")
fi],
[AC_DEFINE(DEFAULT_READNULLCMD,"more")]
)

dnl Do you want to look for pcre support?
AC_ARG_ENABLE(pcre,
AS_HELP_STRING([--enable-pcre],[enable the search for the pcre2 library (may create run-time library dependencies)]))

AC_ARG_VAR(PCRE_CONFIG, [pathname of pcre2-config if it is not in PATH])
if test "x$enable_pcre" = xyes; then
  AC_CHECK_PROG([PCRE_CONFIG], pcre2-config, pcre2-config)
  if test "x$PCRE_CONFIG" = x; then
    enable_pcre=no
    AC_MSG_WARN([pcre2-config not found: pcre module is disabled.])
    AC_MSG_NOTICE(
      [Set PCRE_CONFIG to pathname of pcre2-config if it is not in PATH.])
  fi
fi

dnl Do you want to look for capability support?
AC_ARG_ENABLE(cap,
AS_HELP_STRING([--enable-cap],[enable the search for POSIX capabilities (may require additional headers to be added by hand)]))

# Default off for licensing reasons
AC_ARG_ENABLE(gdbm,
AS_HELP_STRING([--enable-gdbm],[enable the search for the GDBM library (see the zsh/db/gdbm module)]),
[gdbm="$enableval"], [gdbm=no])

dnl ------------------
dnl CHECK THE COMPILER
dnl ------------------
dnl We want these before the checks, so the checks can modify their values.
test -z "${CFLAGS+set}"  && CFLAGS=  auto_cflags=1
test -z "${LDFLAGS+set}" && LDFLAGS= auto_ldflags=1

AC_PROG_CC

dnl Check for large file support.

dnl Gross hack for ReliantUNIX - GCC does not understand getconf options
dnl For now just disable LFS in this case
dnl Any takers?
if test "$host" = mips-sni-sysv4 && test -n "$GCC"; then
  : 
else
  AC_SYS_LARGEFILE
fi

dnl if the user hasn't specified CFLAGS, then
dnl   if compiler is gcc, then use -O2 and some warning flags
dnl   else use -O
if test -n "$auto_cflags"; then
  if test "${enable_zsh_debug}" = yes; then
    if test -n "$GCC"; then
      CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -ggdb"
    else
      CFLAGS="$CFLAGS -g"
    fi
  else
    if test -n "$GCC"; then
      CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -O2"
    else
      CFLAGS="$CFLAGS -O"
    fi
  fi
fi
if test -n "$auto_ldflags"; then
  case "${enable_zsh_debug}$host_os" in
    yesaix*|yeshpux*|yesnetbsd*|yesopenbsd*) ;;  # "ld -g" is not valid on these systems
    darwin*) LDFLAGS=-Wl,-x ;;
    yes*)    LDFLAGS=-g ;;
    *)       LDFLAGS=-s ;;
  esac
fi

dnl ----------
dnl SCO KLUDGE
dnl ----------
dnl Sco doesn't define any useful compiler symbol,
dnl so we will check for sco and define __sco if
dnl found.
case "$host_os" in
  sco*) CFLAGS="-D__sco $CFLAGS" ;;
esac

sed=':1
     s/ -s / /g
     t1
     s/^ *//
     s/ *$//'

case " $LDFLAGS " in
  *" -s "*) strip_exeldflags=true strip_libldflags=true
    LDFLAGS=`echo " $LDFLAGS " | sed "$sed"` ;;
  *) strip_exeldflags=false strip_libldflags=false ;;
esac

case " ${EXELDFLAGS+$EXELDFLAGS }" in
  " ") ;;
  *" -s "*) strip_exeldflags=true
    EXELDFLAGS=`echo " $EXELDFLAGS " | sed "$sed"` ;;
  *) strip_exeldflags=false ;;
esac

case " ${LIBLDFLAGS+$LIBLDFLAGS }" in
  " ") ;;
  *" -s "*) strip_libldflags=true
    LIBLDFLAGS=`echo " $LIBLDFLAGS " | sed "$sed"` ;;
  *) strip_libldflags=false ;;
esac

AC_SUBST(CFLAGS)dnl
AC_SUBST(LDFLAGS)dnl
AC_SUBST(EXELDFLAGS)dnl
AC_SUBST(LIBLDFLAGS)dnl

AC_PROG_CPP                 dnl Figure out how to run C preprocessor.
AC_C_CONST                  dnl Does compiler support `const'.

dnl Default preprocessing on Mac OS X produces warnings
dnl Mac OS X 10.6 (darwin10.x.x) does not need this.
case "$host_os" in
  darwin[[0-9]].*) CPP="$CPP -traditional-cpp" ;;
esac

AC_FUNC_ALLOCA              dnl Check how to get `alloca'.

dnl If the compiler supports union initialisation
AC_CACHE_CHECK(if the compiler supports union initialisation,
zsh_cv_c_have_union_init,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[union{void *p;long l;}u={0};]], [[u.l=1;]])],[zsh_cv_c_have_union_init=yes],[zsh_cv_c_have_union_init=no])])
AH_TEMPLATE([HAVE_UNION_INIT],
[Define to 1 if the compiler can initialise a union.])
if test x$zsh_cv_c_have_union_init = xyes; then
  AC_DEFINE(HAVE_UNION_INIT)
fi

dnl Checking if the compiler supports variable-length arrays
AC_CACHE_CHECK(if the compiler supports variable-length arrays,
zsh_cv_c_variable_length_arrays,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int foo(), n;]], [[int i[foo()], a[n+1];]])],[zsh_cv_c_variable_length_arrays=yes],[zsh_cv_c_variable_length_arrays=no])])
AH_TEMPLATE([HAVE_VARIABLE_LENGTH_ARRAYS],
[Define to 1 if compiler supports variable-length arrays])
if test x$zsh_cv_c_variable_length_arrays = xyes; then
  AC_DEFINE(HAVE_VARIABLE_LENGTH_ARRAYS)
fi

dnl ------------------
dnl CHECK FOR PROGRAMS
dnl ------------------
AC_PROG_MAKE_SET            dnl Does make define $MAKE
AC_PROG_INSTALL             dnl Check for BSD compatible `install'
AC_PROG_AWK                 dnl Check for mawk,gawk,nawk, then awk.
AC_PROG_LN                  dnl Check for working ln, for "make install"
AC_PROG_LN_S                dnl Use ln -s/ln/cp for "make install.runhelp"
AC_PROG_EGREP               dnl sets $EGREP to grep -E or egrep
AC_CHECK_PROGS([YODL], [yodl], [: yodl])

YODL_OPTIONS=''
if test "x$ac_cv_prog_YODL" = xyodl; then
    case `yodl --version` in
      *"version 2."*) YODL_OPTIONS='-k' ;;
      *"version 3."*) YODL_OPTIONS='-k -L' ;;
      *"version 4."*) YODL_OPTIONS='-k -L' ;;
    esac
fi
AC_SUBST(YODL_OPTIONS)

AC_CHECK_PROGS([TEXI2DVI], [texi2dvi], [: texi2dvi])
AC_CHECK_PROGS([TEXI2PDF], [texi2pdf], [: texi2pdf])
AC_CHECK_PROGS([TEXI2HTML], [texi2any texi2html], [: texi2html])

if test x"$TEXI2PDF" != xtexi2pdf && test x"$TEXI2DVI" = xtexi2dvi; then
  TEXI2PDF='texi2dvi --pdf'
fi

if test x"$TEXI2HTML" = xtexi2any; then
  TEXI2HTML='texi2any -c TEXI2HTML=1'
  case `texi2any --version 2>/dev/null | sed -e 's/^.*) *//' -e 1q` in
    [[1-6]].*) SET_TEXI2ANY_VAR=set_from_init_file ;;
    *) SET_TEXI2ANY_VAR=texinfo_set_from_init_file ;;
  esac
fi
AC_SUBST(SET_TEXI2ANY_VAR)

case "$LC_PAPER" in
  ??_US*) PAPERSIZE=us ;;
  *)      PAPERSIZE=a4 ;;
esac
AC_SUBST(PAPERSIZE)

dnl ------------------
dnl CHECK HEADER FILES
dnl ------------------
AC_HEADER_DIRENT
AC_HEADER_STAT
AC_HEADER_SYS_WAIT

dnl pcre2-config --cflags may produce a -I output which needs to go into
dnl CPPFLAGS else configure's preprocessor tests don't pick it up,
dnl producing a warning.
if test "x$enable_pcre" = xyes; then
  CPPFLAGS="`$PCRE_CONFIG --cflags` $CPPFLAGS"
  AC_CHECK_HEADERS([pcre2.h],,,[#define PCRE2_CODE_UNIT_WIDTH 8])
fi

AC_CHECK_HEADERS(sys/time.h sys/times.h sys/select.h termcap.h termio.h \
		 termios.h sys/param.h sys/filio.h \
		 limits.h fcntl.h libc.h sys/utsname.h sys/resource.h \
		 sys/sysctl.h sys/random.h \
		 locale.h errno.h stdio.h stdarg.h varargs.h stdlib.h \
		 unistd.h sys/capability.h \
		 utmp.h utmpx.h sys/types.h pwd.h grp.h poll.h sys/mman.h \
		 netinet/in_systm.h langinfo.h wchar.h stddef.h \
		 sys/stropts.h iconv.h ncurses.h ncursesw/ncurses.h \
		 ncurses/ncurses.h)
if test x$dynamic = xyes; then
  AC_CHECK_HEADERS(dlfcn.h)
  AC_CHECK_HEADERS(dl.h)
fi

dnl Some SCO systems cannot include both sys/time.h and sys/select.h
AH_TEMPLATE([TIME_H_SELECT_H_CONFLICTS],
[Define if sys/time.h and sys/select.h cannot be both included.])
if test x$ac_cv_header_sys_time_h = xyes && test x$ac_cv_header_sys_select_h = xyes; then
  AC_CACHE_CHECK(for conflicts in sys/time.h and sys/select.h,
  zsh_cv_header_time_h_select_h_conflicts,
  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/time.h>
#include <sys/select.h>]], [[int i;]])],[zsh_cv_header_time_h_select_h_conflicts=no],[zsh_cv_header_time_h_select_h_conflicts=yes])])
  if test x$zsh_cv_header_time_h_select_h_conflicts = xyes; then
    AC_DEFINE(TIME_H_SELECT_H_CONFLICTS)
  fi
fi

AH_TEMPLATE([GWINSZ_IN_SYS_IOCTL],
[Define if TIOCGWINSZ is defined in sys/ioctl.h but not in termios.h.])
if test x$ac_cv_header_termios_h = xyes; then
  AC_CACHE_CHECK(TIOCGWINSZ in termios.h,
  zsh_cv_header_termios_h_tiocgwinsz,
  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <termios.h>]], [[int x = TIOCGWINSZ;]])],[zsh_cv_header_termios_h_tiocgwinsz=yes],[zsh_cv_header_termios_h_tiocgwinsz=no])])
else
  zsh_cv_header_termios_h_tiocgwinsz=no
fi
if test x$zsh_cv_header_termios_h_tiocgwinsz = xno; then
  AC_CACHE_CHECK(TIOCGWINSZ in sys/ioctl.h,
  zsh_cv_header_sys_ioctl_h_tiocgwinsz,
  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <sys/ioctl.h>]], [[int x = TIOCGWINSZ;]])],[zsh_cv_header_sys_ioctl_h_tiocgwinsz=yes],[zsh_cv_header_sys_ioctl_h_tiocgwinsz=no])])
  if test x$zsh_cv_header_sys_ioctl_h_tiocgwinsz = xyes; then
    AC_DEFINE(GWINSZ_IN_SYS_IOCTL)
  fi
fi
 
AH_TEMPLATE([WINSIZE_IN_PTEM],
[Define if your should include sys/stream.h and sys/ptem.h.])
AC_CACHE_CHECK(for streams headers including struct winsize,
ac_cv_winsize_in_ptem,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/stream.h>
#include <sys/ptem.h>]], [[struct winsize wsz]])],[ac_cv_winsize_in_ptem=yes],[ac_cv_winsize_in_ptem=no])])
if test x$ac_cv_winsize_in_ptem = xyes; then
  AC_DEFINE(WINSIZE_IN_PTEM)
fi

dnl -------------------
dnl CHECK FOR LIBRARIES
dnl -------------------

dnl On some systems, modules need to be linked against libc explicitly,
dnl in case they require objects that exist only in the static version
dnl and might not be compiled into the zsh executable.
dnl On ReliantUNIX -lc better be the last library, else funny things
dnl may happen.
AC_CHECK_LIB(c, printf, [LIBS="$LIBS -lc"])

AC_CHECK_LIB(m, pow)

AC_CHECK_LIB(rt, clock_gettime)

dnl Various features of ncurses depend on having the right header
dnl (the system's own curses.h may well not be good enough).
dnl So don't search for ncurses unless we found the header.
if test x$ac_cv_header_ncurses_h = xyes || test x$ac_cv_header_ncurses_ncurses_h = xyes || test x$ac_cv_header_ncursesw_ncurses_h = xyes; then
  ncursesw_test=ncursesw
  ncurses_test=ncurses
else
  ncursesw_test=
  ncurses_test=
fi

dnl Prefer BSD termcap library to SysV curses library, except on certain
dnl SYSV-derived systems.  However, if we find terminfo and termcap
dnl stuff in the same library we will use that; typically this
dnl is ncurses or curses.
dnl On pre-11.11 HPUX, Hcurses is reported to work better than curses.
dnl Prefer ncurses to curses on all systems.  tinfo isn't very common now.
AC_ARG_WITH(term-lib,
AS_HELP_STRING([--with-term-lib=LIBS],[search space-separated LIBS for terminal handling]),
[if test "x$withval" != xno && test "x$withval" != x ; then
  termcap_curses_order="$withval"
  AC_SEARCH_LIBS(tigetstr, [$termcap_curses_order])
else
  termcap_curses_order="$ncursesw_test $ncurses_test tinfow tinfo termcap curses"
fi],
[case "$host_os" in
  solaris*)
   termcap_curses_order="$ncursesw_test $ncurses_test curses termcap" ;;
  hpux10.*|hpux11.*)
   DL_EXT="${DL_EXT=sl}"
   termcap_curses_order="Hcurses $ncursesw_test $ncurses_test curses termcap" ;;
  *)
   termcap_curses_order="$ncursesw_test $ncurses_test tinfow tinfo termcap curses" ;;
esac])dnl

AH_TEMPLATE([ZSH_NO_XOPEN],
[Define if _XOPEN_SOURCE_EXTENDED should not be defined to avoid clashes])
AC_CACHE_CHECK(if _XOPEN_SOURCE_EXTENDED should not be defined,
zsh_cv_no_xopen,
[[case "$host_os" in
  *freebsd5*|*freebsd6.[012]*|*aix*)
  zsh_cv_no_xopen=yes
  ;;
  *)
  zsh_cv_no_xopen=no
  ;;
esac]])
if test x$zsh_cv_no_xopen = xyes; then
  AC_DEFINE(ZSH_NO_XOPEN)
fi

dnl Check for tigetflag (terminfo) before tgetent (termcap).
dnl That's so that on systems where termcap and [n]curses are
dnl both available and both contain termcap functions, while
dnl only [n]curses contains terminfo functions, we only link against
dnl [n]curses.
LIBS_save_pre_term="$LIBS"
AC_SEARCH_LIBS(tigetstr, [$termcap_curses_order])
AC_SEARCH_LIBS(tigetflag, [$termcap_curses_order])
AC_SEARCH_LIBS(tgetent, [$termcap_curses_order],
  true,
  AC_MSG_FAILURE(["No terminal handling library was found on your system.
This is probably a library called 'curses' or 'ncurses'.  You may
need to install a package called 'curses-devel' or 'ncurses-devel' on your
system."], 255))
AC_CHECK_HEADERS(curses.h, [],
[AC_CACHE_CHECK(for Solaris 8 curses.h mistake, ac_cv_header_curses_solaris,
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curses.h>]], [[]])],[ac_cv_header_curses_h=yes
ac_cv_header_curses_solaris=yes],[ac_cv_header_curses_h=no
ac_cv_header_curses_solaris=no]))
if test x$ac_cv_header_curses_solaris = xyes; then
AC_DEFINE(HAVE_CURSES_H)
fi])

dnl If our terminal library is not ncurses, don't try including
dnl any ncurses headers.
AC_CACHE_CHECK(if we need to ignore ncurses, zsh_cv_ignore_ncurses,
[case $LIBS in
  *-lncurses*)
  zsh_cv_ignore_ncurses=no
  ;;
  *)
    dnl The lack of -lncurses in the $LIBS might be the result of passing
    dnl --with-term-lib=^ncurses option. To address this, a test for the tgetent
    dnl and other functions is ran here, possibly for the second time, just to
    dnl ensure that the ncurses library doesn't have them.
    LIBS_save="$LIBS"
    dnl Remember (the values are used later, around line 3005) and remove the cache
    ac_cv_search_tigetstr_SAVE="$ac_cv_search_tigetstr"
    ac_cv_search_tigetnum_SAVE="$ac_cv_search_tigetnum"
    ac_cv_search_tigetflag_SAVE="$ac_cv_search_tigetflag"
    ac_cv_search_tgetent_SAVE="$ac_cv_search_tgetent"
    unset ac_cv_search_tigetstr ac_cv_search_tigetnum ac_cv_search_tigetflag ac_cv_search_tgetent
    LIBS="$LIBS_save_pre_term"

    dnl Run the checks for all four used terminal functions
    AC_SEARCH_LIBS(tigetstr, [ncursesw ncurses curses])
    AC_SEARCH_LIBS(tigetnum, [ncursesw ncurses curses])
    AC_SEARCH_LIBS(tigetflag, [ncursesw ncurses curses])
    AC_SEARCH_LIBS(tgetent, [ncursesw ncurses curses])
    LIBS_result="$LIBS"

    LIBS="$LIBS_save"
    dnl Restore the cache
    ac_cv_search_tigetstr="$ac_cv_search_tigetstr_SAVE"
    ac_cv_search_tigetnum="$ac_cv_search_tigetnum_SAVE"
    ac_cv_search_tigetflag="$ac_cv_search_tigetflag_SAVE"
    ac_cv_search_tgetent="$ac_cv_search_tgetent_SAVE"

    case $LIBS_result in
      *-lncurses*|*-lcurses*)
        dnl Yes we need to ignore ncurses, its tgetent or tigetflag might
        dnl conflict with the one from the selected terminal library
        zsh_cv_ignore_ncurses=yes
        ;;
      *)
        dnl If the tgetent nor tigetflag weren't found in the libncurses*.so, then
        dnl there will be no conflict with the other terminal library selected (e.g.
        dnl libtinfo) and it's possible to link ncurses provided that it is working
        dnl - it is here verified that it has initscr() function to check that
        AC_SEARCH_LIBS(initscr, [ncursesw ncurses curses])
        case $LIBS in
          *-lncurses*|*-lcurses*)
            dnl No need to ignore curses - it is working and it doesn't
            dnl have tgetent nor tigetflag
            zsh_cv_ignore_ncurses=no
          ;;
          *)
            zsh_cv_ignore_ncurses=yes
          ;;
        esac
    esac
  ;;
esac])

AC_SEARCH_LIBS(getpwnam, nsl)

if test "x$dynamic" = xyes; then
  AC_CHECK_LIB(dl, dlopen)
fi

if test x$enable_cap = xyes; then
  AC_CHECK_LIB(cap, cap_get_proc)
fi

AC_CHECK_LIB(socket, socket)
AC_SEARCH_LIBS(gethostbyname2, bind)

case $LIBS in
  *-lbind*)
  AC_CHECK_HEADERS(bind/netdb.h)
  ;;
esac

dnl ---------------
dnl CHECK FOR ICONV
dnl ---------------

dnl Find iconv. It may be in libiconv and may be iconv() or libiconv()
if test "x$ac_cv_header_iconv_h" = "xyes"; then
  AC_CHECK_FUNC(iconv, ac_found_iconv=yes, ac_found_iconv=no)
  if test "x$ac_found_iconv" = "xno"; then
    AC_CHECK_LIB(iconv, iconv, ac_found_iconv=yes)
    if test "x$ac_found_iconv" = "xno"; then
      AC_CHECK_LIB(iconv, libiconv, ac_found_iconv=yes)
    fi
    if test "x$ac_found_iconv" != "xno"; then
      LIBS="-liconv $LIBS"
    fi
  else
    dnl Handle case where there is a native iconv but iconv.h is from libiconv
    AC_CHECK_DECL(_libiconv_version,
      [ AC_CHECK_LIB(iconv, libiconv, LIBS="-liconv $LIBS") ],,
      [ #include <iconv.h> ])
  fi
fi
AH_TEMPLATE([ICONV_FROM_LIBICONV],
[Define to 1 if iconv() is linked from libiconv])
if test "x$ac_found_iconv" = xyes; then
  AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <iconv.h>]], [[int myversion = _libiconv_version]])],[AC_DEFINE(ICONV_FROM_LIBICONV)],[])
fi

dnl Check if iconv uses const in prototype declaration
if test "x$ac_found_iconv" = "xyes"; then
  AC_CACHE_CHECK(for iconv declaration, ac_cv_iconv_const,
    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
        #include <iconv.h>]],
        [[#ifdef __cplusplus
          "C"
          #endif
          #if defined(__STDC__) || defined(__cplusplus)
          size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
          #else
          size_t iconv();
          #endif]])],
      [ac_cv_iconv_const=],
      [ac_cv_iconv_const=const])])
  AC_DEFINE_UNQUOTED([ICONV_CONST], $ac_cv_iconv_const,
    [Define as const if the declaration of iconv() needs const.])
fi

dnl ---------------------
dnl CHECK TERMCAP LIBRARY
dnl ---------------------
dnl Checks for external variable ospeed in the termcap library.
AC_CACHE_CHECK(if an include file defines ospeed,
zsh_cv_decl_ospeed_include_defines,
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#if HAVE_TERMIOS_H
#include <termios.h>
#endif
#if HAVE_TERMCAP_H
#include <termcap.h>
#endif]], [[ospeed = 0;]])],[zsh_cv_decl_ospeed_include_defines=yes],[zsh_cv_decl_ospeed_include_defines=no])])

if test x$zsh_cv_decl_ospeed_include_defines = xno; then
  AC_CACHE_CHECK(if you must define ospeed,
  zsh_cv_decl_ospeed_must_define,
  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[extern short ospeed; ospeed = 0;]])],[zsh_cv_decl_ospeed_must_define=yes],[zsh_cv_decl_ospeed_must_define=no])])
fi

AH_TEMPLATE([HAVE_OSPEED],
[Define to 1 if your termcap library has the ospeed variable])
AH_TEMPLATE([MUST_DEFINE_OSPEED],
[Define to 1 if you have ospeed, but it is not defined in termcap.h])
if test x$zsh_cv_decl_ospeed_include_defines = xyes; then
  AC_DEFINE(HAVE_OSPEED)
elif test x$zsh_cv_decl_ospeed_must_define = xyes; then
  AC_DEFINE(HAVE_OSPEED)
  AC_DEFINE(MUST_DEFINE_OSPEED)
fi

if test x$gdbm != xno; then
  AC_CHECK_HEADERS(gdbm.h)
  AC_CHECK_LIB(gdbm, gdbm_open)
fi

AC_CHECK_HEADERS(sys/xattr.h)

dnl --------------
dnl CHECK TYPEDEFS
dnl --------------

AC_TYPE_PID_T
AC_TYPE_OFF_T
AC_CHECK_TYPE(ino_t, unsigned long)
AC_TYPE_MODE_T
AC_TYPE_UID_T
AC_TYPE_SIZE_T

dnl ------------------------------------------------
dnl Check size of long and try to find a 64-bit type
dnl ------------------------------------------------
dnl AC_CHECK_SIZEOF is no good, because we need the result here,
dnl and that doesn't seem to define a shell parameter.
AC_CACHE_CHECK(if long is 64 bits, zsh_cv_long_is_64_bit,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[int main() { return sizeof(long) < 8; }]])],[zsh_cv_long_is_64_bit=yes],[zsh_cv_long_is_64_bit=no],[zsh_cv_long_is_64_bit=no])])

AH_TEMPLATE([ino_t],
[Define to `unsigned long' if <sys/types.h> doesn't define.])
AH_TEMPLATE([LONG_IS_64_BIT],
[Definitions used when a long is less than eight byte, to try to
 provide some support for eight byte operations.

 Note that ZSH_64_BIT_TYPE, OFF_T_IS_64_BIT, INO_T_IS_64_BIT do *not* get
 defined if long is already 64 bits, since in that case no special handling
 is required.

 Define to 1 if long is 64 bits])
AH_TEMPLATE([ZSH_64_BIT_TYPE],
[Define to a 64 bit integer type if there is one, but long is shorter.])
AH_TEMPLATE([ZSH_64_BIT_UTYPE],
[Define to an unsigned variant of ZSH_64_BIT_TYPE if that is defined.])
AH_TEMPLATE([OFF_T_IS_64_BIT],
[Define to 1 if off_t is 64 bit (for large file support)])
AH_TEMPLATE([INO_T_IS_64_BIT],
[Define to 1 if ino_t is 64 bit (for large file support).])
if test x$zsh_cv_long_is_64_bit = xyes; then
  AC_DEFINE(LONG_IS_64_BIT)
else
  AC_CACHE_CHECK(if off_t is 64 bit, zsh_cv_off_t_is_64_bit,
  [AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <sys/types.h>

int main() { return sizeof(off_t) < 8; }
]])],[zsh_cv_off_t_is_64_bit=yes],[zsh_cv_off_t_is_64_bit=no],[zsh_cv_off_t_is_64_bit=no])])
  if test x$zsh_cv_off_t_is_64_bit = xyes; then
    AC_DEFINE(OFF_T_IS_64_BIT)
  fi

  AC_CACHE_CHECK(if ino_t is 64 bit, zsh_cv_ino_t_is_64_bit,
  [AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <sys/types.h>

int main() { return sizeof(ino_t) < 8; }
]])],[zsh_cv_ino_t_is_64_bit=yes],[zsh_cv_ino_t_is_64_bit=no],[zsh_cv_ino_t_is_64_bit=no])])
  if test x$zsh_cv_ino_t_is_64_bit = xyes; then
    AC_DEFINE(INO_T_IS_64_BIT)
  fi

  if test x$enable_largefile != xno -o x$zsh_cv_off_t_is_64_bit = xyes \
  -o $zsh_cv_ino_t_is_64_bit = yes; then
    AC_CACHE_CHECK(if compiler has a 64 bit type, zsh_cv_64_bit_type,
    [zsh_64_BIT_TYPE(long long, zsh_cv_64_bit_type)
     if test "$zsh_cv_64_bit_type" = no; then
       zsh_64_BIT_TYPE(quad_t, zsh_cv_64_bit_type)
     fi
     if test "$zsh_cv_64_bit_type" = no; then
       zsh_64_BIT_TYPE(__int64_t, zsh_cv_64_bit_type)
     fi
     dnl As a last resort, if we know off_t has 64 bits, use that as
     dnl the 64-bit integer type.  I don't dare try ino_t since there's
     dnl probably nothing to stop that being unsigned.
     if test "$zsh_cv_64_bit_type" = no &&
        test "$zsh_cv_off_t_is_64_bit" = yes; then
       zsh_64_BIT_TYPE(off_t, zsh_cv_64_bit_type)
     fi])
    if test "$zsh_cv_64_bit_type" != no; then
      AC_DEFINE_UNQUOTED(ZSH_64_BIT_TYPE, $zsh_cv_64_bit_type)

      dnl Handle cases where unsigned type cannot be simply
      dnl `unsigned ZSH_64_BIT_TYPE'.  More tests may be required.
      AC_CACHE_CHECK(for a corresponding unsigned 64 bit type,
      zsh_cv_64_bit_utype,
      [zsh_64_BIT_TYPE(unsigned $zsh_cv_64_bit_type, zsh_cv_64_bit_utype,
       force)
       if test "$zsh_cv_64_bit_utype" = no; then
         zsh_64_BIT_TYPE(__uint64_t, zsh_cv_64_bit_utype)
       fi])
      if test "$zsh_cv_64_bit_utype" != no; then
        AC_DEFINE_UNQUOTED(ZSH_64_BIT_UTYPE, $zsh_cv_64_bit_utype)
      fi
    fi
  fi
fi
AH_TEMPLATE([ZLONG_IS_LONG_LONG],
[Define to 1 if the zlong type uses long long int.])
AH_TEMPLATE([ZLONG_IS_LONG_64],
[Define to 1 if the zlong type uses 64-bit long int.])
if test "$zsh_cv_64_bit_type" = "long long"; then
  dnl Remember this so we can get (s)printf output right.
  AC_DEFINE(ZLONG_IS_LONG_LONG)
else
  if test "$zsh_cv_64_bit_type" = "long"; then
      AC_DEFINE(ZLONG_IS_LONG_64)
  fi
fi

dnl We'll blithely assume (f)printf supports the same types as sprintf.
AC_CACHE_CHECK(for %lld printf support, zsh_cv_printf_has_lld,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
   long long foo = ((long long)0xdead << 40) | 0xf00d;
   char buf[80];
   sprintf(buf, "before%lldafter", foo);
   if (!strcmp(buf, "before62677660341432333after")) {
      return 0;
   }
   return 1;
}
]])],[zsh_cv_printf_has_lld=yes],[zsh_cv_printf_has_lld=no],[zsh_cv_printf_has_lld=no])])
AH_TEMPLATE(PRINTF_HAS_LLD,
[Define to 1 if printf and sprintf support %lld for long long.])
if test x$zsh_cv_printf_has_lld = xyes; then
  AC_DEFINE(PRINTF_HAS_LLD)
fi

dnl Check for sigset_t.  Currently I'm looking in
dnl <sys/types.h> and <signal.h>.  Others might need
dnl to be added.
AC_CACHE_CHECK(for sigset_t, zsh_cv_type_sigset_t,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <signal.h>]], [[sigset_t tempsigset;]])],[zsh_cv_type_sigset_t=yes],[zsh_cv_type_sigset_t=no])])
AH_TEMPLATE([sigset_t],
[Define to `unsigned int' if <sys/types.h> or <signal.h> doesn't define])
if test x$zsh_cv_type_sigset_t = xno; then
  AC_DEFINE(sigset_t, unsigned int)
fi

dnl check structures for high resolution timestamps
AC_CHECK_MEMBERS([struct stat.st_atim.tv_nsec,
                  struct stat.st_atimespec.tv_nsec,
                  struct stat.st_atimensec,
                  struct stat.st_mtim.tv_nsec,
                  struct stat.st_mtimespec.tv_nsec,
                  struct stat.st_mtimensec,
                  struct stat.st_ctim.tv_nsec,
                  struct stat.st_ctimespec.tv_nsec,
                  struct stat.st_ctimensec])

dnl Check for struct timezone since some old SCO versions do not define it
zsh_TYPE_EXISTS([
#define _GNU_SOURCE 1
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
], struct timezone)

dnl Check for struct timespec since POSIX only gained it in 2008
zsh_TYPE_EXISTS([
#define _GNU_SOURCE 1
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
], struct timespec)

dnl Check for utmp structures, for watch
zsh_TYPE_EXISTS([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UTMP_H
# include <utmp.h>
#endif
], struct utmp)
zsh_TYPE_EXISTS([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UTMPX_H
# include <utmpx.h>
#endif
], struct utmpx)

dnl Check contents of utmp structures
zsh_STRUCT_MEMBER([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UTMP_H
# include <utmp.h>
#endif
], struct utmp, ut_host)
zsh_STRUCT_MEMBER([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UTMPX_H
# include <utmpx.h>
#endif
], struct utmpx, ut_host)
zsh_STRUCT_MEMBER([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UTMPX_H
# include <utmpx.h>
#endif
], struct utmpx, ut_xtime)
zsh_STRUCT_MEMBER([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UTMPX_H
# include <utmpx.h>
#endif
], struct utmpx, ut_tv)

dnl Check for inode numbers in directory entry structures
zsh_STRUCT_MEMBER([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_DIRENT_H
# include <dirent.h>
#endif
], struct dirent, d_ino)
zsh_STRUCT_MEMBER([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_DIRENT_H
# include <dirent.h>
#endif
], struct dirent, d_stat)
zsh_STRUCT_MEMBER([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
#endif
#ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
#endif
#ifdef HAVE_NDIR_H
# include <ndir.h>
#endif
], struct direct, d_ino)
zsh_STRUCT_MEMBER([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_NDIR_H
# include <sys/ndir.h>
#endif
#ifdef HAVE_SYS_DIR_H
# include <sys/dir.h>
#endif
#ifdef HAVE_NDIR_H
# include <ndir.h>
#endif
], struct direct, d_stat)

dnl Check IPv6 socket address structure type
zsh_STRUCT_MEMBER([
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <netinet/in.h>
], struct sockaddr_in6, sin6_scope_id)

dnl Check for h_errno external variable
AH_TEMPLATE([USE_LOCAL_H_ERRNO],
[Define to 1 if h_errno is not defined by the system.])
AC_CACHE_CHECK(if we need our own h_errno,
  zsh_cv_decl_h_errno_use_local,
  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[extern int h_errno; h_errno = 0;]])],[zsh_cv_decl_h_errno_use_local=no],[zsh_cv_decl_h_errno_use_local=yes])])

if test x$zsh_cv_decl_h_errno_use_local = xyes; then
  AC_DEFINE(USE_LOCAL_H_ERRNO)
fi

dnl ---------------
dnl CHECK FUNCTIONS
dnl ---------------

dnl need to integrate this function
dnl AC_FUNC_STRFTIME

AC_CHECK_FUNCS(strftime strptime mktime timelocal \
	       difftime gettimeofday clock_gettime \
	       select poll \
	       readlink faccessx fchdir ftruncate \
	       fstat lstat lchown fchown fchmod \
	       fpurge fseeko ftello \
	       mkfifo _mktemp mkstemp \
	       waitpid wait3 \
	       sigqueue \
	       killpg setpgid setpgrp tcsetpgrp tcgetattr nice \
	       gethostname gethostbyname2 getipnodebyname \
	       inet_aton inet_pton inet_ntop \
	       getlogin getpwent getpwnam getpwuid getgrgid getgrnam \
	       initgroups \
	       setuid seteuid setreuid setresuid setsid \
	       setgid setegid setregid setresgid \
	       memcpy memmove strstr strerror strtoul \
	       getrlimit getrusage \
	       setlocale \
	       isblank iswblank \
	       uname \
	       signgam tgamma \
	       log2 \
	       scalbn \
	       putenv getenv setenv unsetenv \
	       brk sbrk \
	       pathconf sysconf \
	       tgetent tigetflag tigetnum tigetstr setupterm initscr resize_term \
	       getcchar setcchar waddwstr wget_wch win_wch use_default_colors \
	       nl_langinfo \
	       erand48 open_memstream \
	       posix_openpt \
	       wctomb iconv \
	       grantpt unlockpt ptsname \
	       htons ntohs \
	       regcomp regexec regerror regfree \
	       gdbm_open getxattr \
	       realpath canonicalize_file_name \
	       symlink getcwd \
	       cygwin_conv_path \
	       nanosleep \
	       srand_deterministic \
	       getrandom arc4random_buf \
	       setutxent getutxent endutxent getutent)
AC_FUNC_STRCOLL

# isinf() and isnan() can exist as either functions or macros.
AH_TEMPLATE([HAVE_ISINF],
  [Define to 1 if you have the `isinf' macro or function.])
AC_MSG_CHECKING([for isinf])
AC_LINK_IFELSE([AC_LANG_SOURCE(
[[#include <math.h>
int main () { return (isinf(1.0) != 0); }]])],
  [AC_MSG_RESULT([yes])
   AC_DEFINE([HAVE_ISINF])],
  [AC_MSG_RESULT([no])])

AH_TEMPLATE([HAVE_ISNAN],
  [Define to 1 if you have the `isnan' macro or function.])
AC_MSG_CHECKING([for isnan])
AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include <math.h>
int main () { return (isnan(1.0) != 0); }]])],
  [AC_MSG_RESULT([yes])
   AC_DEFINE([HAVE_ISNAN])],
  [AC_MSG_RESULT([no])])

AH_TEMPLATE([REALPATH_ACCEPTS_NULL],
[Define if realpath() accepts NULL as its second argument.])
AC_CACHE_CHECK([if realpath accepts NULL],
zsh_cv_func_realpath_accepts_null,
[AC_RUN_IFELSE([AC_LANG_PROGRAM([
#include <stdlib.h>
#include <limits.h>
],[
return(!realpath("/", (char*)0));
])],
[zsh_cv_func_realpath_accepts_null=yes],
[zsh_cv_func_realpath_accepts_null=no],
[zsh_cv_func_realpath_accepts_null=$ac_cv_func_canonicalize_file_name])])
if test x$zsh_cv_func_realpath_accepts_null = xyes; then
  AC_DEFINE(REALPATH_ACCEPTS_NULL)
fi

if test x$enable_pcre = xyes; then
  LIBS="`$PCRE_CONFIG --libs8` $LIBS"
  AC_CHECK_FUNCS(pcre2_compile_8)
fi

if test x$enable_cap = xyes; then
  AC_CHECK_FUNCS(cap_get_proc)
fi

dnl  Check if tgetent accepts NULL (and will allocate its own termcap buffer)
dnl  Some termcaps reportedly accept a zero buffer, but then dump core
dnl  in tgetstr().
dnl  Under Cygwin test program crashes but exit code is still 0. So,
dnl  we test for a file that porgram should create
AH_TEMPLATE([TGETENT_ACCEPTS_NULL],
[Define to 1 if tgetent() accepts NULL as a buffer.])
AC_CACHE_CHECK(if tgetent accepts NULL,
zsh_cv_func_tgetent_accepts_null,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <fcntl.h>
int tgetent(char *, char *);
char *tgetstr(char *, char **);
int main()
{
    char buf[4096];
    int r1 = tgetent(buf, "vt100");
    int r2 = tgetent((char*)0,"vt100");
    if (r1 >= 0 && r1 == r2) {
        char tbuf[1024], *u;
        u = tbuf;
    	tgetstr("cl", &u);
	creat("conftest.tgetent", 0640);
    }
    return((r1 != r2) || r2 == -1);
}
]])],[if test -f conftest.tgetent; then
    zsh_cv_func_tgetent_accepts_null=yes
  else
    zsh_cv_func_tgetent_accepts_null=no
  fi],[zsh_cv_func_tgetent_accepts_null=no],[zsh_cv_func_tgetent_accepts_null=no])])
if test x$zsh_cv_func_tgetent_accepts_null = xyes; then
  AC_DEFINE(TGETENT_ACCEPTS_NULL)
fi
AC_CACHE_CHECK(if tgetent returns 0 on success,
zsh_cv_func_tgetent_zero_success,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <fcntl.h>
int tgetent(char *, char*);
char *tgetstr(char *, char **);
int main()
{
    char buf[4096];
    int r1 = tgetent(buf, "!@#$%^&*");
    int r2 = tgetent(buf, "vt100");
    if (r1 < 0 && r2 == 0) {
        char tbuf[1024], *u;
        u = tbuf;
    	tgetstr("cl", &u);
	creat("conftest.tgetent0", 0640);
    }
    return(r1 == r2);
}
]])],[if test -f conftest.tgetent0; then
    zsh_cv_func_tgetent_zero_success=yes
  else
    zsh_cv_func_tgetent_zero_success=no
  fi],[zsh_cv_func_tgetent_zero_success=no],[zsh_cv_func_tgetent_zero_success=no])])
AH_TEMPLATE([TGETENT_SUCCESS],
[Define to what tgetent() returns on success (0 on HP-UX X/Open curses).])
if test x$zsh_cv_func_tgetent_zero_success = xyes; then
  AC_DEFINE(TGETENT_SUCCESS, 0)
else
  AC_DEFINE(TGETENT_SUCCESS, 1)
fi

AC_FUNC_MMAP
if test x$ac_cv_func_mmap_fixed_mapped = xyes; then
  AC_CHECK_FUNCS(munmap msync)
fi

if test x$ac_cv_func_setpgrp = xyes; then
  AC_FUNC_GETPGRP
else
  dnl If there is no setpgrp, the test for getpgrp(void) will fail
  dnl because the program will not compile.  However, in that case
  dnl we can be reasonably confident we are not dealing with a
  dnl Berkeleyesque system, so assume getpgrp does take void.
  ac_cv_func_getpgrp_void=yes
  AC_DEFINE(GETPGRP_VOID)
fi

if test x$dynamic = xyes; then
  AC_CHECK_FUNCS(dlopen dlerror dlsym dlclose load loadquery loadbind unload \
		shl_load shl_unload shl_findsym)
fi

AH_TEMPLATE([XATTR_EXTRA_ARGS],
Define if getxattr() etc. require additional MacOS-style arguments)
if test x$ac_cv_func_getxattr = xyes && test x$ac_cv_header_sys_xattr_h = xyes
then
  AC_CACHE_CHECK(if getxattr etc. are Linux-like,
  zsh_cv_getxattr_linux,
  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <sys/xattr.h>]],
  [[
  (void)listxattr("", 0, 0);
  (void)getxattr("", "", 0, 0);
  (void)setxattr("", "", "", 0, 0);
  (void)removexattr("", "");
  ]])],
  [zsh_cv_getxattr_linux=yes],
  [zsh_cv_getxattr_linux=no])])

  if test x$zsh_cv_getxattr_linux != xyes; then
    AC_CACHE_CHECK(if getxattr etc. are MAC-like,
    zsh_cv_getxattr_mac,
    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
#include <sys/xattr.h>]],
    [[(void)listxattr("", 0, 0, 0);
    (void)getxattr("", "", 0, 0, 0, 0);
    (void)setxattr("", "", "", 0, 0, 0);
    (void)removexattr("", "", 0);]])],
    [zsh_cv_getxattr_mac=yes],
    [zsh_cv_getxattr_mac=no])])

    if test x$zsh_cv_getxattr_mac = xyes; then
      AC_DEFINE(XATTR_EXTRA_ARGS)
    fi
  fi
fi

AC_CACHE_CHECK(if getxattr etc. are usable,
zsh_cv_use_xattr,
[if test x$zsh_cv_getxattr_linux = xyes || test x$zsh_cv_getxattr_mac = xyes
then
zsh_cv_use_xattr=yes
else
zsh_cv_use_xattr=no
fi])

dnl We don't want to use setenv(3) on El Capitan or older OS X because it
dnl removes a leading '=' from the value of the environment variable
AH_TEMPLATE([SETENV_MANGLES_EQUAL],
[Define to 1 if setenv removes a leading =])
case $host_os in
  darwin1[0-5]*) AC_DEFINE(SETENV_MANGLES_EQUAL) ;;
esac

dnl Where is <signal.h> located?  Needed as input for signals.awk
AC_CACHE_CHECK(where signal.h is located, zsh_cv_path_signal_h,
[dnl Look at the output from the preprocessor.
dnl We should get lines of the form `# 1 "/usr/include/signal.h"'
dnl The following assumes the real definitions are in a file which
dnl contains the name `sig'; we could relax this if necessary,
dnl but then you can get a rather long list of files to test.
dnl The backslash substitution is to persuade cygwin to cough up
dnl slashes rather than doubled backslashes in the path.
echo "#include <signal.h>" > nametmp.c
sigfile_list="`$CPP $CPPFLAGS nametmp.c |
sed -n -e 's/^#line[ 	].*\"\(.*\)\"/\1/p' \
       -e 's/^#[ 	].*\"\(.*\)\"/\1/p' |
sed 's/\\\\\\\\/\//g' |
$AWK '{ if ($1 ~ /sig/) files[[$1]] = $1 }
  END { for (var in files) print var }'`"
rm -f nametmp.c
if test -z "$sigfile_list"; then
  dnl In case we don't get the stuff from the preprocesor, use the old
  dnl list of standard places.
  sigfile_list="/usr/include/sys/iso/signal_iso.h
/usr/include/bsd/sys/signal.h
/usr/include/signum.h
/usr/include/asm/signum.h
/usr/include/asm/signal.h
/usr/include/linux/signal.h
/usr/include/sys/signal.h
/usr/include/bits/signum.h
/dev/null"
fi
for SIGNAL_TRY_H in $sigfile_list
do
  dnl Try to make sure it doesn't get confused by files that don't
  dnl have real signal definitions in, but do #define SIG* by counting
  dnl the number of signals.  Maybe we could even check for e.g. SIGHUP?
  nsigs=`test -f $SIGNAL_TRY_H && \
  grep '#[ 	]*define[ 	][ 	]*SIG[0-9A-Z]*[ 	]*[0-9][0-9]*' $SIGNAL_TRY_H | \
  wc -l | sed 's/[ 	]//g'`
  if test "x$nsigs" != x && test "$nsigs" -ge 7
  then
    SIGNAL_H="$SIGNAL_H $SIGNAL_TRY_H"
  fi
done
if test "x$SIGNAL_H" = x; then
  AC_MSG_ERROR(SIGNAL MACROS NOT FOUND:  please report to developers)
fi
zsh_cv_path_signal_h="$SIGNAL_H"
])
SIGNAL_H="$zsh_cv_path_signal_h"
AC_SUBST(SIGNAL_H)dnl

dnl Where are error names located?  Needed as input for errnames1.awk
AC_CACHE_CHECK(where error names are located, zsh_cv_path_errno_h,
[dnl Look at the output from the preprocessor.
dnl We should get lines of the form `# 1 "/usr/include/errno.h"'
dnl The following assumes the real definitions are in a file which
dnl contains the name `err'; we could relax this if necessary,
dnl but then you can get a rather long list of files to test.
dnl The backslash substitution is to persuade cygwin to cough up
dnl slashes rather than doubled backslashes in the path.
echo "#include <errno.h>" > nametmp.c
errfile_list="`$CPP $CPPFLAGS nametmp.c |
sed -n -e 's/^#line[ 	].*\"\(.*\)\"/\1/p' \
       -e 's/^#[ 	0-9].*\"\(.*\)\"/\1/p' |
sed 's/\\\\\\\\/\//g' |
$AWK '{ if ($1 ~ /err/) files[[$1]] = $1 }
  END { for (var in files) print var }'`"
rm -f nametmp.c
for ERRNO_TRY_H in $errfile_list /dev/null
do
  dnl Try to make sure it doesn't get confused by files that don't
  dnl have real error definitions in.  Count definitions to make sure.
  dnl Definitions of error numbers have become more and more general, so
  dnl make a list of files containing any definitions in and keep them all.
  dnl Careful with cut and paste in the pattern: the square brackets
  dnl must contain a space and a tab.
  nerrs=`test -f $ERRNO_TRY_H && \
  $EGREP '#[ 	]*define[ 	][ 	]*E[0-9A-Z]*[ 	]*(_HURD_ERRNO )?\(?[_A-Z0-9]' $ERRNO_TRY_H | \
  wc -l | sed 's/[ 	]//g'`
  if test "x$nerrs" != x && test "$nerrs" -ge 1
  then
    ERRNO_H="$ERRNO_H $ERRNO_TRY_H"
  fi
done
if test x"$ERRNO_H" = x; then
  AC_MSG_ERROR(ERROR MACROS NOT FOUND:  please report to developers)
fi
zsh_cv_path_errno_h="$ERRNO_H"
])
ERRNO_H="$zsh_cv_path_errno_h"
AC_SUBST(ERRNO_H)dnl

AC_CACHE_CHECK(location of curses header, zsh_cv_path_curses_header,
[if test x$zsh_cv_ignore_ncurses = xyes; then
  if test x$ac_cv_header_curses_h = xyes; then
    zsh_cv_path_curses_header=curses.h
  else
    zsh_cv_path_curses_header=none
  fi
elif test x$ac_cv_header_ncursesw_ncurses_h = xyes; then
  zsh_cv_path_curses_header=ncursesw/ncurses.h
elif test x$ac_cv_header_ncurses_ncurses_h = xyes; then
  zsh_cv_path_curses_header=ncurses/ncurses.h
elif test x$ac_cv_header_ncurses_h = xyes; then
  zsh_cv_path_curses_header=ncurses.h
elif test x$ac_cv_header_curses_h = xyes; then
  zsh_cv_path_curses_header=curses.h
else
  zsh_cv_path_curses_header=none
fi])
AH_TEMPLATE([ZSH_HAVE_CURSES_H],
[Define to 1 if some variant of a curses header can be included])
if test x$zsh_cv_path_curses_header != xnone; then
  AC_DEFINE(ZSH_HAVE_CURSES_H)
  ZSH_CURSES_H=$zsh_cv_path_curses_header
else
  ZSH_CURSES_H=
fi
AC_SUBST(ZSH_CURSES_H)

dnl Where are curses key definitions located?  Need for keypad() mode.
AC_CACHE_CHECK(where curses key definitions are located, zsh_cv_path_curses_keys_h,
[dnl This is an identical trick to errno.h, except we use ncurses.h
dnl if we can.
if test x$zsh_cv_path_curses_header = xnone; then
  echo >nametmp.c
else
  echo "#include <$zsh_cv_path_curses_header>" >nametmp.c
fi

curses_list="`$CPP $CPPFLAGS nametmp.c |
sed -n -e 's/^#line[ 	].*\"\(.*\)\"/\1/p' \
       -e 's/^#[ 	0-9].*\"\(.*\)\"/\1/p' |
sed 's/\\\\\\\\/\//g' |
$AWK '{ if ($1 ~ /\.h/) files[[$1]] = $1 }
  END { for (var in files) print var }'`"
rm -f nametmp.c
for CURSES_TRY_H in $curses_list /dev/null
do
  nkeys=`test -f $CURSES_TRY_H && \
  $EGREP '#[ 	]*define[ 	][ 	]*KEY_' $CURSES_TRY_H | \
  wc -l | sed 's/[ 	]//g'`
  if test "x$nkeys" != x && test "$nkeys" -ge 10
  then
    CURSES_KEYS_H=$CURSES_TRY_H
    break
  fi
done
zsh_cv_path_curses_keys_h="$CURSES_KEYS_H"
])
CURSES_KEYS_H="$zsh_cv_path_curses_keys_h"
AC_SUBST(CURSES_KEYS_H)dnl

dnl See if there are variants of term.h.  For testing each one
dnl we include the most likely variant of the curses header.
AC_CHECK_HEADERS(ncursesw/term.h,
true, true,
[#include <ncursesw/ncurses.h>])
AC_CHECK_HEADERS(ncurses/term.h,
true, true,
[#include <ncurses/ncurses.h>])
AC_CHECK_HEADERS(term.h,
true, true,
[#include <curses.h>])

dnl See if term.h is bundled along with the curses library we
dnl are using.  If this isn't the default system curses, compilation
dnl could barf unless we include from the right subdirectory.
AC_CACHE_CHECK(where term.h is located, zsh_cv_path_term_header,
[case x$zsh_cv_path_curses_header in
  xncursesw/*)
  if test x$ac_cv_header_ncursesw_term_h = xyes; then
    zsh_cv_path_term_header=ncursesw/term.h
  fi
  ;;
  xncurses/*)
  if test x$ac_cv_header_ncurses_term_h = xyes; then
    zsh_cv_path_term_header=ncurses/term.h
  fi
  ;;
esac
if test x$zsh_cv_path_term_header = x; then
  if test x$ac_cv_header_term_h = xyes; then
    zsh_cv_path_term_header=term.h
  else
    zsh_cv_path_term_header=none
  fi
fi])

AH_TEMPLATE([ZSH_HAVE_TERM_H],
[Define to 1 if some variant of term.h can be included])
AH_TEMPLATE([HAVE_BOOLCODES],
[Define if you have the termcap boolcodes symbol.])
AH_TEMPLATE([HAVE_NUMCODES],
[Define if you have the termcap numcodes symbol.])
AH_TEMPLATE([HAVE_STRCODES],
[Define if you have the termcap strcodes symbol.])
AH_TEMPLATE([HAVE_BOOLNAMES],
[Define if you have the terminfo boolnames symbol.])
AH_TEMPLATE([HAVE_NUMNAMES],
[Define if you have the terminfo numnames symbol.])
AH_TEMPLATE([HAVE_STRNAMES],
[Define if you have the terminfo strnames symbol.])
AH_TEMPLATE([TGOTO_PROTO_MISSING],
[Define if there is no prototype for the tgoto() terminal function.])

if test x$zsh_cv_path_term_header != xnone; then
  AC_DEFINE(ZSH_HAVE_TERM_H)
  ZSH_TERM_H=$zsh_cv_path_term_header
  if test x$zsh_cv_path_curses_header != xnone; then
    term_includes="#include <$zsh_cv_path_curses_header>
#include <$zsh_cv_path_term_header>"
  else
    term_includes="#include <$zsh_cv_path_term_header>"
  fi

  AC_MSG_CHECKING(if boolcodes is available)
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[$term_includes]], [[char **test = (char **)boolcodes; puts(*test);]])],[AC_DEFINE(HAVE_BOOLCODES) boolcodes=yes],[boolcodes=no])
  AC_MSG_RESULT($boolcodes)

  AC_MSG_CHECKING(if numcodes is available)
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[$term_includes]], [[char **test = (char **)numcodes; puts(*test);]])],[AC_DEFINE(HAVE_NUMCODES) numcodes=yes],[numcodes=no])
  AC_MSG_RESULT($numcodes)

  AC_MSG_CHECKING(if strcodes is available)
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[$term_includes]], [[char **test = (char **)strcodes; puts(*test);]])],[AC_DEFINE(HAVE_STRCODES) strcodes=yes],[strcodes=no])
  AC_MSG_RESULT($strcodes)

  AC_MSG_CHECKING(if boolnames is available)
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[$term_includes]], [[char **test = (char **)boolnames; puts(*test);]])],[AC_DEFINE(HAVE_BOOLNAMES) boolnames=yes],[boolnames=no])
  AC_MSG_RESULT($boolnames)

  AC_MSG_CHECKING(if numnames is available)
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[$term_includes]], [[char **test = (char **)numnames; puts(*test);]])],[AC_DEFINE(HAVE_NUMNAMES) numnames=yes],[numnames=no])
  AC_MSG_RESULT($numnames)

  AC_MSG_CHECKING(if strnames is available)
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[$term_includes]], [[char **test = (char **)strnames; puts(*test);]])],[AC_DEFINE(HAVE_STRNAMES) strnames=yes],[strnames=no])
  AC_MSG_RESULT($strnames)

  dnl There are apparently defective terminal library headers on some
  dnl versions of Solaris before 11.
  AC_MSG_CHECKING(if tgoto prototype is missing)
  tgoto_includes="$term_includes
/* guaranteed to clash with any valid tgoto prototype */
extern void tgoto(int **stuff, float **more_stuff);"
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[$tgoto_includes]], [[int *stuff; float *more_stuff; tgoto(&stuff, &more_stuff);]])],[AC_DEFINE(TGOTO_PROTO_MISSING) tgotoprotomissing=yes],[tgotoprotomissing=no])
  AC_MSG_RESULT($tgotoprotomissing)
else
  ZSH_TERM_H=
fi
AC_SUBST(ZSH_TERM_H)


dnl -----------------------------------------------------
dnl Look for the file containing the RLIMIT_* definitions
dnl -----------------------------------------------------
dnl CALL FOR MORE (FEWER?) LOCATIONS:  I've just copied the signal checking.
AC_CACHE_CHECK(where the RLIMIT macros are located,zsh_cv_path_rlimit_h,
[dnl Look at the output from the preprocessor.
dnl Copied from the search for the signal names above.
echo "#include <sys/resource.h>" >restmp.c
resourcefile_list="`$CPP $CPPFLAGS restmp.c |
sed -n -e 's/^#line[ 	].*\"\(.*\)\"/\1/p' \
       -e 's/^#[ 	].*\"\(.*\)\"/\1/p' |
sed 's/\\\\\\\\/\//g' |
$AWK '{ if ($1 ~ /resource/) files[[$1]] = $1 }
  END { for (var in files) print var }'`"
rm -f restmp.c
if test -z "$resourcefile_list"; then
  dnl No list: look at standard places.
  resourcefile_list="/usr/include/bsd/sys/resource.h
/usr/include/asm/resource.h
/usr/include/linux/resource.h
/usr/include/sys/resource.h
/usr/include/bits/resource.h
/usr/include/resourcebits.h"
fi
for RESOURCE_H in $resourcefile_list /dev/null;
do
  test -f $RESOURCE_H && \
  grep '#[ 	]*define[ 	][ 	]*RLIMIT_[A-Z]*[ 	]*[0-9A-Z][0-9]*' $RESOURCE_H > /dev/null && \
  break
done
zsh_cv_path_rlimit_h=$RESOURCE_H
if test x$RESOURCE_H = x"/dev/null" && test x$ac_cv_func_getrlimit = xyes; then
  AC_MSG_WARN(RLIMIT MACROS NOT FOUND:  please report to developers)
fi])
RLIMITS_INC_H=$zsh_cv_path_rlimit_h
if test "$RLIMITS_INC_H" = "/dev/null"; then
  RLIMITS_INC_H=''
fi
dnl rlimits.h only appears in dependencies if we are actually using it.
dnl We are using it any time we have getrlimit, though if the macros were
dnl not found we simply awk through /dev/null and fail to find them.
dnl Thus, limit won't work, but at least the shell will compile.
AC_SUBST(RLIMITS_INC_H)dnl

dnl ------------------
dnl rlimit type checks
dnl ------------------
AH_TEMPLATE([RLIM_T_IS_QUAD_T],
[Define to 1 if struct rlimit uses quad_t.])
AH_TEMPLATE([RLIM_T_IS_LONG_LONG],
[Define to 1 if struct rlimit uses long long])
AH_TEMPLATE([RLIM_T_IS_UNSIGNED],
[Define to 1 if struct rlimit uses unsigned.])
AH_TEMPLATE([rlim_t],
[Define to the type used in struct rlimit.])
DEFAULT_RLIM_T=long
AC_CACHE_CHECK(if rlim_t is longer than a long,
zsh_cv_rlim_t_is_longer,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/resource.h>
int main(){struct rlimit r;return(sizeof(r.rlim_cur) <= sizeof(long));}]])],[zsh_cv_rlim_t_is_longer=yes],[zsh_cv_rlim_t_is_longer=no],[zsh_cv_rlim_t_is_longer=yes])])
if test x$zsh_cv_rlim_t_is_longer = xyes; then
  AC_CACHE_CHECK(if rlim_t is a quad,
  zsh_cv_rlim_t_is_quad_t,
  [AC_RUN_IFELSE([AC_LANG_SOURCE([[
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <stdio.h>
#include <sys/resource.h>
int main() {
  struct rlimit r;
  char buf[20];
  r.rlim_cur = 0;
  sprintf(buf, "%qd", r.rlim_cur);
  return(strcmp(buf, "0"));
}]])],[zsh_cv_rlim_t_is_quad_t=yes],[zsh_cv_rlim_t_is_quad_t=no],[zsh_cv_rlim_t_is_quad_t=no])])
  if test x$zsh_cv_rlim_t_is_quad_t = xyes; then
    AC_DEFINE(RLIM_T_IS_QUAD_T)
    DEFAULT_RLIM_T=quad_t
  else
    AC_DEFINE(RLIM_T_IS_LONG_LONG)
    DEFAULT_RLIM_T='long long'
  fi
else
  AC_CACHE_CHECK(if the rlim_t is unsigned,
  zsh_cv_type_rlim_t_is_unsigned,
  [AC_RUN_IFELSE([AC_LANG_SOURCE([[
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/resource.h>
  int main(){struct rlimit r;r.rlim_cur=-1;return(r.rlim_cur<0);}]])],[zsh_cv_type_rlim_t_is_unsigned=yes],[zsh_cv_type_rlim_t_is_unsigned=no],[zsh_cv_type_rlim_t_is_unsigned=no])])
  if test x$zsh_cv_type_rlim_t_is_unsigned = xyes; then
    AC_DEFINE(RLIM_T_IS_UNSIGNED)
    DEFAULT_RLIM_T="unsigned $DEFAULT_RLIM_T"
  fi
fi

AC_CACHE_CHECK(for rlim_t, zsh_cv_type_rlim_t,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/resource.h>]], [[rlim_t l;]])],[zsh_cv_type_rlim_t=yes],[zsh_cv_type_rlim_t=no])])
if test x$zsh_cv_type_rlim_t = xno; then
  AC_DEFINE_UNQUOTED(rlim_t, $DEFAULT_RLIM_T)
fi


dnl On some systems the RLIMIT_* don't evaluate to integers at compile time
dnl (they may be enums).  In this case we are not able to do preprocessor
dnl comparisons and need our tests to determine what values exist and
dnl if there are clashing definitions.

zsh_LIMIT_PRESENT(RLIMIT_AIO_MEM)
zsh_LIMIT_PRESENT(RLIMIT_AIO_OPS)
zsh_LIMIT_PRESENT(RLIMIT_AS)
zsh_LIMIT_PRESENT(RLIMIT_LOCKS)
zsh_LIMIT_PRESENT(RLIMIT_MEMLOCK)
zsh_LIMIT_PRESENT(RLIMIT_NPROC)
zsh_LIMIT_PRESENT(RLIMIT_NTHR)
zsh_LIMIT_PRESENT(RLIMIT_NOFILE)
zsh_LIMIT_PRESENT(RLIMIT_PTHREAD)
zsh_LIMIT_PRESENT(RLIMIT_RSS)
zsh_LIMIT_PRESENT(RLIMIT_SBSIZE)
zsh_LIMIT_PRESENT(RLIMIT_TCACHE)
zsh_LIMIT_PRESENT(RLIMIT_VMEM)
zsh_LIMIT_PRESENT(RLIMIT_SIGPENDING)
zsh_LIMIT_PRESENT(RLIMIT_MSGQUEUE)
zsh_LIMIT_PRESENT(RLIMIT_NICE)
zsh_LIMIT_PRESENT(RLIMIT_RTPRIO)
zsh_LIMIT_PRESENT(RLIMIT_RTTIME)
zsh_LIMIT_PRESENT(RLIMIT_POSIXLOCKS)
zsh_LIMIT_PRESENT(RLIMIT_NPTS)
zsh_LIMIT_PRESENT(RLIMIT_SWAP)
zsh_LIMIT_PRESENT(RLIMIT_KQUEUES)
zsh_LIMIT_PRESENT(RLIMIT_UMTXP)
zsh_LIMIT_PRESENT(RLIMIT_NOVMON)

zsh_LIMITS_EQUAL(VMEM, vmem, RSS, rss)
zsh_LIMITS_EQUAL(VMEM, vmem, AS, as)
zsh_LIMITS_EQUAL(RSS, rss, AS, as)

dnl --------------------------------------------
dnl Check for members of struct rusage
dnl --------------------------------------------
if test x$ac_cv_func_getrusage = xyes; then
  AC_CHECK_MEMBERS([struct rusage.ru_maxrss,
		    struct rusage.ru_ixrss,
		    struct rusage.ru_idrss,
		    struct rusage.ru_isrss,
		    struct rusage.ru_minflt,
		    struct rusage.ru_majflt,
		    struct rusage.ru_nswap,
		    struct rusage.ru_inblock,
		    struct rusage.ru_oublock,
		    struct rusage.ru_msgsnd,
		    struct rusage.ru_msgrcv,
		    struct rusage.ru_nsignals,
		    struct rusage.ru_nvcsw,
		    struct rusage.ru_nivcsw],,,
[#include <sys/types.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/resource.h>])
fi
dnl On some OSes (only macOS?) ru_maxrss is in bytes (not in kilobytes).
dnl Solaris uses pages as the unit, but ru_maxrss is set to zero anyway.
AH_TEMPLATE(RU_MAXRSS_IS_IN_BYTES,
[Define to 1 if ru_maxrss in struct rusage is in bytes.])
case "$host_os" in
  darwin*)
    AC_DEFINE(RU_MAXRSS_IS_IN_BYTES)
  ;;
esac


dnl --------------------------------------------
dnl CHECK FOR DEFAULT PATH (used for command -p)
dnl --------------------------------------------
AC_CACHE_VAL(zsh_cv_cs_path,
[if getconf _CS_PATH >/dev/null 2>&1; then
  zsh_cv_cs_path=`getconf _CS_PATH`
elif getconf CS_PATH >/dev/null 2>&1; then
  zsh_cv_cs_path=`getconf CS_PATH`
elif getconf PATH >/dev/null 2>&1; then
  zsh_cv_cs_path=`getconf PATH`
else
  zsh_cv_cs_path="/bin:/usr/bin"
fi])
AC_DEFINE_UNQUOTED(DEFAULT_PATH, "$zsh_cv_cs_path",
[The default path; used when running commands with command -p])


dnl ----------------------------
dnl CHECK FOR /dev/fd FILESYSTEM
dnl ----------------------------
dnl FreeBSD 5 only supports /dev/fd/0 to /dev/fd/2 without mounting
dnl a special file system.  As zsh needs arbitrary /dev/fd (typically
dnl >10) for its own use, we need to make sure higher fd's are available.
dnl Since we're using the shell, we're restricted to 0 to 9 but 3 should
dnl be good enough.
AH_TEMPLATE([PATH_DEV_FD],
[Define to the path of the /dev/fd filesystem.])
AC_CACHE_CHECK(for /dev/fd filesystem, zsh_cv_sys_path_dev_fd,
[for zsh_cv_sys_path_dev_fd in /proc/self/fd /dev/fd no; do
   test x`echo ok|(cat $zsh_cv_sys_path_dev_fd/3 3<&0 2>/dev/null;)` = xok && break
 done])
if test x$zsh_cv_sys_path_dev_fd != xno; then
  AC_DEFINE_UNQUOTED(PATH_DEV_FD, "$zsh_cv_sys_path_dev_fd")
fi

dnl ----------------------------------------------------
dnl CHECK FOR SYMLINK TO THE CURRENT EXECUTABLE IN /proc
dnl ----------------------------------------------------
dnl Linux: /proc/self/exe
dnl NetBSD: /proc/curproc/exe (or /proc/self/exe, but not /proc/curproc/file)
dnl DragonFly: /proc/curproc/file
dnl Solaris: /proc/self/path/a.out
AH_TEMPLATE([PROC_SELF_EXE],
[Define to the path of the symlink to the current executable file.])
AC_CACHE_CHECK(for symlink to the current executable in /proc,
zsh_cv_proc_self_exe,
[for zsh_cv_proc_self_exe in /proc/self/exe /proc/curproc/exe \
                             /proc/curproc/file /proc/self/path/a.out no; do
   test -L $zsh_cv_proc_self_exe && break
done])
if test x$zsh_cv_proc_self_exe != xno; then
  AC_DEFINE_UNQUOTED(PROC_SELF_EXE, "$zsh_cv_proc_self_exe")
fi

dnl ---------------------------------
dnl CHECK FOR RFS SUPERROOT DIRECTORY
dnl ---------------------------------
AC_CACHE_CHECK(for RFS superroot directory, zsh_cv_sys_superroot,
[test -d /../.LOCALROOT && zsh_cv_sys_superroot=yes || zsh_cv_sys_superroot=no])
AH_TEMPLATE([HAVE_SUPERROOT],
[Define to 1 if you have RFS superroot directory.])
if test x$zsh_cv_sys_superroot = xyes; then
  AC_DEFINE(HAVE_SUPERROOT)
fi

dnl CHECK FOR SYSTEMS REQUIRING GETCWD
dnl This is now turned on by default, as we expect modern getcwd
dnl implementations to work correctly.  Any exceptions should be added
dnl to the first case.  Currently there are none, hence it is forced
dnl not to match.
AC_CACHE_CHECK(whether we should use the native getcwd,
zsh_cv_use_getcwd,
[case "${host_cpu}-${host_vendor}-${host_os}" in
    *NOMATCH*) zsh_cv_use_getcwd=no ;;
    *) zsh_cv_use_getcwd=yes ;;
 esac])
AH_TEMPLATE([USE_GETCWD],
[Define to 1 if you need to use the native getcwd.])
if test x$zsh_cv_use_getcwd = xyes; then
  AC_DEFINE(USE_GETCWD)
fi

dnl GNU getcwd() can allocate as much space as necessary for a
dnl directory name, preventing guessing games.
AH_TEMPLATE([GETCWD_CALLS_MALLOC],
[Define to 1 if getcwd() calls malloc to allocate memory.])
if test x$ac_cv_func_getcwd = xyes; then
  AC_CACHE_CHECK(whether getcwd calls malloc to allocate memory,
  zsh_cv_getcwd_malloc,
  [AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <unistd.h>
#include <string.h>
int main() {
    char buf[1024], *ptr1, *ptr2;
    ptr1 = getcwd(buf, 1024);
    ptr2 = getcwd(NULL, 0);
    if (ptr1 && ptr2 && !strcmp(ptr1, ptr2)) {
      return 0;
    }
    return 1;
}
]])],[zsh_cv_getcwd_malloc=yes],[zsh_cv_getcwd_malloc=no],[zsh_cv_getcwd_malloc=no])])
  if test x$zsh_cv_getcwd_malloc = xyes; then
    AC_DEFINE(GETCWD_CALLS_MALLOC)
  fi
fi

dnl CHECK FOR setproctitle() FOR jobs -Z / ARGV0
AH_TEMPLATE([HAVE_SETPROCTITLE],
[Define to 1 if the system supports `setproctitle' to change process name])
AC_CHECK_FUNC(setproctitle,AC_DEFINE(HAVE_SETPROCTITLE),
AC_SEARCH_LIBS(setproctitle,util,AC_DEFINE(HAVE_SETPROCTITLE)))

dnl CHECK FOR prctl() FOR jobs -Z / ARGV0 when checking with ps -e
AH_TEMPLATE([HAVE_PRCTL],
[Define to 1 if the system supports `prctl' to change process name])
AC_CHECK_FUNC(prctl,AC_DEFINE(HAVE_PRCTL),
AC_SEARCH_LIBS(prctl,c,AC_DEFINE(HAVE_PRCTL)))

dnl ----------------------------------------
dnl CHECK FOR LOCATION OF {U,W}TMP{,X} FILES
dnl ----------------------------------------
zsh_PATH_UTMP(utmp)
zsh_PATH_UTMP(wtmp)
zsh_PATH_UTMP(utmpx,utx.active)
zsh_PATH_UTMP(wtmpx)

dnl -------------------
dnl brk/sbrk PROTOTYPES
dnl -------------------
AC_CACHE_CHECK(for brk() prototype in <unistd.h>,
zsh_cv_header_unistd_h_brk_proto,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
double brk();]], [[int i;]])],[zsh_cv_header_unistd_h_brk_proto=no],[zsh_cv_header_unistd_h_brk_proto=yes])])
AH_TEMPLATE([HAVE_BRK_PROTO],
[Define to 1 if there is a prototype defined for brk() on your system.])
if test x$zsh_cv_header_unistd_h_brk_proto = xyes; then
  AC_DEFINE(HAVE_BRK_PROTO)
fi

AC_CACHE_CHECK(for sbrk() prototype in <unistd.h>,
zsh_cv_header_unistd_h_sbrk_proto,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>
double sbrk();]], [[int i;]])],[zsh_cv_header_unistd_h_sbrk_proto=no],[zsh_cv_header_unistd_h_sbrk_proto=yes])])
AH_TEMPLATE([HAVE_SBRK_PROTO],
[Define to 1 if there is a prototype defined for sbrk() on your system.])
if test x$zsh_cv_header_unistd_h_sbrk_proto = xyes; then
  AC_DEFINE(HAVE_SBRK_PROTO)
fi

dnl -----------------------
dnl mknod prototype for OSF
dnl -----------------------
AH_TEMPLATE([HAVE_MKNOD_PROTO],
[Define to 1 if there is a prototype defined for mknod() on your system.])
if test "$ac_cv_prog_cc_stdc" != no; then
  AC_CACHE_CHECK(for mknod prototype in <sys/stat.h>,
  zsh_cv_header_sys_stat_h_mknod_proto,
  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/stat.h>
   int mknod(double x);]], [[int i;]])],[zsh_cv_header_sys_stat_h_mknod_proto=no],[zsh_cv_header_sys_stat_h_mknod_proto=yes])])
  if test x$zsh_cv_header_sys_stat_h_mknod_proto = xyes; then
    AC_DEFINE(HAVE_MKNOD_PROTO)
  fi
fi

dnl ----------------------------------------
dnl presence and location of ioctl prototype
dnl ----------------------------------------
AC_CACHE_CHECK(for ioctl prototype in <unistd.h> or <termios.h>,
zsh_cv_header_unistd_h_termios_h_ioctl_proto,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_TERMIOS_H
# include <termios.h>
#endif
double ioctl();]], [[int i;]])],[zsh_cv_header_unistd_h_termios_h_ioctl_proto=no],[zsh_cv_header_unistd_h_termios_h_ioctl_proto=yes])])

if test x$zsh_cv_header_unistd_h_termios_h_ioctl_proto = xno; then
  AC_CACHE_CHECK(for ioctl prototype in <sys/ioctl.h>,
  zsh_cv_header_sys_ioctl_h_ioctl_proto,
  [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/ioctl.h>
  double ioctl();]], [[int i;]])],[zsh_cv_header_sys_ioctl_h_ioctl_proto=no],[zsh_cv_header_sys_ioctl_h_ioctl_proto=yes])])
else
  zsh_cv_header_sys_ioctl_h_ioctl_proto=no
fi

AH_TEMPLATE([HAVE_IOCTL_PROTO],
[Define to 1 if there is a prototype defined for ioctl() on your system.])
if test x$zsh_cv_header_unistd_h_termios_h_ioctl_proto = xyes || \
   test x$zsh_cv_header_sys_ioctl_h_ioctl_proto = xyes; then
  AC_DEFINE(HAVE_IOCTL_PROTO)
fi
AH_TEMPLATE([IOCTL_IN_SYS_IOCTL],
[Define to 1 if we must include <sys/ioctl.h> to get a prototype for ioctl().])
if test x$zsh_cv_header_sys_ioctl_h_ioctl_proto = xyes; then
  AC_DEFINE(IOCTL_IN_SYS_IOCTL)
fi

dnl -----------
dnl named FIFOs
dnl -----------
dnl
AC_CACHE_CHECK(if named FIFOs work,
zsh_cv_sys_fifo,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
#include <sys/stat.h>
int main()
{
    char c;
    int fd;
    int pid, ret;
    unlink("/tmp/fifo$$");
#ifdef HAVE_MKFIFO
    if(mkfifo("/tmp/fifo$$", 0600) < 0)
#else
    if(mknod("/tmp/fifo$$", 0010600, 0) < 0)
#endif
	return(1);
    pid = fork();
    if(pid < 0)
	return(1);
    if(pid) {
	fd = open("/tmp/fifo$$", O_RDONLY);
	return(fd < 0 || read(fd, &c, 1) != 1 || c != 'x');
    }
    fd = open("/tmp/fifo$$", O_WRONLY);
    ret = (fd < 0 || write(fd, "x", 1) < 1);
    unlink("/tmp/fifo$$");
    return(ret);
}
]])],[zsh_cv_sys_fifo=yes],[zsh_cv_sys_fifo=no],[zsh_cv_sys_fifo=yes])
])
AH_TEMPLATE([HAVE_FIFOS],
[Define to 1 if system has working FIFOs.])
if test x$zsh_cv_sys_fifo = xyes; then
  AC_DEFINE(HAVE_FIFOS)
fi

dnl -----------
dnl check that lseek() correctly reports seekability.
dnl -----------
AC_CACHE_CHECK(if lseek() correctly reports seekability,
zsh_cv_sys_lseek,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/stat.h>
int main() {
    int pipefd[2], fd;
    off_t ret;
    char* tmpfile = "seekfiletest.tmp";
    if ((fd = open(tmpfile, O_CREAT, S_IRUSR)) < 0) {
	fprintf(stderr, "creating file failed\n");
	return 1;
    }
    ret = lseek(fd, 0, SEEK_CUR);
    close(fd);
    unlink(tmpfile);
    if (ret == (off_t)-1) {
	fprintf(stderr, "lseek on regular file failed\n");
	return 1;
    }
    if (pipe(pipefd) < 0) {
	fprintf(stderr, "creating pipe failed\n");
	return 1;
    }
    write(pipefd[1], "abcdefgh", 8);
    ret = lseek(pipefd[0], 0, SEEK_CUR);
    close(pipefd[0]);
    close(pipefd[1]);
    if (ret != (off_t)-1) {
	fprintf(stderr, "lseek on pipe succeeded\n");
	return 1;
    }
    if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
	fprintf(stderr, "creating UNIX domain socket failed\n");
	return 1;
    }
    ret = lseek(fd, 0, SEEK_CUR);
    close(fd);
    if (ret != (off_t)-1) {
	fprintf(stderr, "lseek on UNIX domain socket succeeded\n");
	return 1;
    }
    return 0;
}
]])],[zsh_cv_sys_lseek=yes],[zsh_cv_sys_lseek=no],[zsh_cv_sys_lseek=yes])
])
AH_TEMPLATE([USE_LSEEK],
[Define to 1 if lseek() can be used for SHIN.])
if test x$zsh_cv_sys_lseek = xyes; then
  AC_DEFINE(USE_LSEEK)
fi

dnl -----------
dnl test for whether link() works
dnl for instance, BeOS R4.51 doesn't support hard links yet
dnl -----------
AC_CACHE_CHECK(if link() works,
zsh_cv_sys_link,
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <unistd.h>
#include <fcntl.h>
int main()
{
    int ret;
    char *tmpfile, *newfile;
    tmpfile="/tmp/zsh.linktest$$";
    newfile="/tmp/zsh.linktest2$$";
    unlink(tmpfile);
    unlink(newfile);
    if(creat(tmpfile, 0644) < 0)
	return(1);
    ret = link(tmpfile, newfile);
    unlink(tmpfile);
    unlink(newfile);
    return(ret<0);
}
]])],[zsh_cv_sys_link=yes],[zsh_cv_sys_link=no],[zsh_cv_sys_link=yes])])
AH_TEMPLATE([HAVE_LINK],
[Define to 1 if system has working link().])
if test x$zsh_cv_sys_link = xyes; then
  AC_DEFINE(HAVE_LINK)
fi

dnl ---------------
dnl check for the type of third argument of accept
dnl ---------------

zsh_CHECK_SOCKLEN_T

dnl ---------------
dnl Check for pty multiplexer for use in pty module.
dnl We need to open it read/write, so make sure it is writeable.
dnl Yet another test which won't work when cross-compiling.
dnl ---------------
AC_CACHE_CHECK(if your system has /dev/ptmx,
ac_cv_have_dev_ptmx,
[if test -w /dev/ptmx; then
  ac_cv_have_dev_ptmx=yes
else
  ac_cv_have_dev_ptmx=no
fi])

dnl --------
dnl Check if the ptmx functions are usable.
dnl We need to be able to find the prototypes, which may
dnl require non-POSIX source definitions.  So test to see
dnl if ptsname is correctly recognised as returning a char *.
dnl We do this by making sure a program where ptsname() is declared
dnl as returning int does *not* compile.
dnl On Linux we need the XOPEN extensions.  The easiest way to get
dnl these is by defining _GNU_SOURCE.
dnl -------
AH_TEMPLATE([USE_DEV_PTMX],
[Define to 1 if all the kit for using /dev/ptmx for ptys is available.])
if test x$ac_cv_have_dev_ptmx = xyes -o x$ac_cv_func_posix_openpt = xyes && \
   test x$ac_cv_func_grantpt = xyes && \
   test x$ac_cv_func_unlockpt = xyes && \
   test x$ac_cv_func_ptsname = xyes; then
   AC_CACHE_CHECK([if /dev/ptmx is usable],
   ac_cv_use_dev_ptmx,
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#if defined(__linux) || defined(__CYGWIN__)
#define _GNU_SOURCE 1
#endif
#include <stdlib.h>
int ptsname();]], [[]])],[ac_cv_use_dev_ptmx=no],[ac_cv_use_dev_ptmx=yes])])
   if test x$ac_cv_use_dev_ptmx = xyes; then
     AC_DEFINE(USE_DEV_PTMX)
   fi
fi

dnl -----------------
dnl multibyte support
dnl -----------------
AC_ARG_ENABLE(multibyte,
AS_HELP_STRING([--enable-multibyte],[support multibyte characters]),
[zsh_cv_c_unicode_support=$enableval],
[AC_CACHE_VAL(zsh_cv_c_unicode_support,
  AC_MSG_NOTICE([checking for functions supporting multibyte characters])
  [zfuncs_absent=
dnl
dnl Note that iswblank is not included and checked separately.
dnl As iswblank() was added to C long after the others, we still
dnl want to enabled unicode support even if iswblank is not available
dnl (we then just do the SPC+TAB approximation)
dnl
   for zfunc in iswalnum iswcntrl iswdigit iswgraph iswlower iswprint \
iswpunct iswspace iswupper iswxdigit mbrlen mbrtowc towupper towlower \
wcschr wcscpy wcslen wcsncmp wcsncpy wcrtomb wcwidth wmemchr wmemcmp \
wmemcpy wmemmove wmemset; do
     AC_CHECK_FUNC($zfunc,
     [:], [zfuncs_absent="$zfuncs_absent $zfunc"])
    done
    if test x"$zfuncs_absent" = x; then
      AC_MSG_NOTICE([all functions found, multibyte support enabled])
      zsh_cv_c_unicode_support=yes
    else
      # Warns at the end of configure
      AC_MSG_NOTICE([missing functions, multibyte support disabled])
      zsh_cv_c_unicode_support=no
    fi
  ])
])
AH_TEMPLATE([MULTIBYTE_SUPPORT],
[Define to 1 if you want support for multibyte character sets.])

dnl
dnl unicode9 support
dnl
AH_TEMPLATE([ENABLE_UNICODE9],
[Define to 1 if you want use unicode9 character widths.])
AC_ARG_ENABLE(unicode9,
AS_HELP_STRING([--enable-unicode9],[compile with unicode9 character widths]),
[if test x$enableval = xyes; then
  AC_DEFINE(ENABLE_UNICODE9)
fi])

AH_TEMPLATE([BROKEN_ISPRINT],
[Define to 1 if the isprint() function is broken under UTF-8 locale.])

if test x$zsh_cv_c_unicode_support = xyes; then
  AC_DEFINE(MULTIBYTE_SUPPORT)

  dnl Test if wcwidth() and/or iswprint() is broken for
  dnl   zero-width combining characters, or
  dnl   some characters in the Latin Extended-B.
  dnl If either of the functions is broken, both functions will be replaced
  dnl by the ones from wcwidth9.h by defining ENABLE_UNICODE9. We will do
  dnl this only if __STDC_ISO_10646__ is defined (or if building on macOS,
  dnl where __STDC_ISO_10646__ is not defined but wchar_t is UCS).
  dnl For the test we use a combining acute accent (\u0301) or
  dnl a LATIN SMALL LETTER L WITH CURL (\u0234).
  dnl We input it as UTF-8 since that is the standard we can rely
  dnl upon most:  we can't rely on a wchar_t being stored as a
  dnl Unicode code point on all systems.
  dnl The programme returns 0 only if all the conditions for brokenness
  dnl are met:
  dnl - the programme compiled, linked and ran
  dnl - we successfully set a UTF-8 locale
  dnl - the locale we set plausibly converted the UTF-8 string
  dnl   into the correct wide character
  dnl - but wcwidth() or iswprint() is broken for the converted wide character.
  dnl locale -a is a fallback; on most systems we should find en_US.UTF-8.
  [locale_prog='char *my_locales[] = {
  "en_US.UTF-8", "en_GB.UTF-8", "en.UTF-8", '
  locale_prog="$locale_prog"`locale -a 2>/dev/null | \
    sed -e 's/utf8/UTF-8/' | grep UTF-8 | \
    while read line; do echo " \"$line\","; done;`
  locale_prog="$locale_prog 0 };
  #define _XOPEN_SOURCE
  #include <stdlib.h>
  #include <locale.h>
  #include <wchar.h>
  #include <wctype.h>

  int main() {
    char **localep;
    char comb_acute_mb[] = { (char)0xcc, (char)0x81 };
    char u_0234[] = { (char)0xc8, (char)0xb4 };
    wchar_t wc;
  #if !defined(__STDC_ISO_10646__) && !defined(__APPLE__)
    return 1;
  #endif

    for (localep = my_locales; *localep; localep++)
      if (setlocale(LC_ALL, *localep))
	  break;
    if (!*localep)
      return 1;
    if (mbtowc(&wc, comb_acute_mb, 2) == 2 && (wcwidth(wc) != 0 || !iswprint(wc)))
      return 0;
    if (mbtowc(&wc, u_0234, 2) == 2 && (wcwidth(wc) != 1 || !iswprint(wc)))
      return 0;
    return 1;
  }
  "]

  AC_CACHE_CHECK(if the wcwidth() and/or iswprint() functions are broken,
  zsh_cv_c_broken_wcwidth,
  [AC_RUN_IFELSE([AC_LANG_SOURCE([[$locale_prog]])],[zsh_cv_c_broken_wcwidth=yes],[zsh_cv_c_broken_wcwidth=no],[zsh_cv_c_broken_wcwidth=no])])
  if test x$zsh_cv_c_broken_wcwidth = xyes; then
    AC_DEFINE(ENABLE_UNICODE9)
  fi

  dnl Check if isprint() behaves correctly under UTF-8 locale.
  dnl On some platform (maybe only on Mac OS X), isprint() returns
  dnl true for all characters in the range from 0xa0 to 0xff if
  dnl called under UTF-8 locale.
  [locale_prog='char *my_locales[] = {
  "en_US.UTF-8", "en_GB.UTF-8", "en.UTF-8", '
  locale_prog="$locale_prog"`locale -a 2>/dev/null | \
    sed -e 's/utf8/UTF-8/' | grep UTF-8 | \
    while read line; do echo " \"$line\","; done;`
  locale_prog="$locale_prog 0 };
  #include <locale.h>
  #include <ctype.h>

  int main() {
    char **localep;
    for (localep = my_locales; *localep; localep++)
      if (setlocale(LC_ALL, *localep) && isprint(0xa0))
	return 0;
    return 1;
  }
  "]

  AC_CACHE_CHECK(if the isprint() function is broken,
  zsh_cv_c_broken_isprint,
  [AC_RUN_IFELSE([AC_LANG_SOURCE([[$locale_prog]])],[zsh_cv_c_broken_isprint=yes],[zsh_cv_c_broken_isprint=no],[zsh_cv_c_broken_isprint=no])])
  if test x$zsh_cv_c_broken_isprint = xyes; then
    AC_DEFINE(BROKEN_ISPRINT)
  fi
fi

dnl
dnl musl support
dnl
AH_TEMPLATE([LIBC_MUSL],
[Define to 1 if musl is being used as the C library])
AC_ARG_ENABLE(libc-musl,
AS_HELP_STRING([--enable-libc-musl],[compile with musl as the C library]),
[if test x$enableval = xyes; then
  AC_DEFINE(LIBC_MUSL)
fi])

dnl
dnl static user lookup
dnl
AC_ARG_ENABLE(dynamic-nss,
	      AS_HELP_STRING([--disable-dynamic-nss],[do not call
			      functions that will require dynamic NSS
			      modules]),
[zsh_cv_c_dynamic_nss=$enableval],
[])

AH_TEMPLATE([DISABLE_DYNAMIC_NSS],
[Define to 1 if you want to avoid calling functions that will require
 dynamic NSS modules.])
if test x$zsh_cv_c_dynamic_nss = xno; then
  AC_DEFINE(DISABLE_DYNAMIC_NSS)
fi

dnl ---------------
dnl dynamic loading
dnl ---------------
AH_TEMPLATE([HPUX10DYNAMIC],
[Define to 1 if you want to use dynamically loaded modules on HPUX 10.])
L=N
INSTLIB="install.bin-\$(L)"
UNINSTLIB="uninstall.bin-\$(L)"
LINKMODS=NOLINKMODS
MOD_EXPORT=
MOD_IMPORT_VARIABLE=
MOD_IMPORT_FUNCTION=
aixdynamic=no
hpuxdynamic=no
if test "$ac_cv_func_load"      = yes &&
   test "$ac_cv_func_unload"    = yes &&
   test "$ac_cv_func_loadbind"  = yes &&
   test "$ac_cv_func_loadquery" = yes; then
  dnl Force AIXDYNAMIC even on newer versions that have dl family
  if test "x$dynamic" = xyes; then
    aixdynamic=yes
  fi
elif test "$ac_cv_func_dlopen"  != yes ||
     test "$ac_cv_func_dlsym"   != yes ||
     test "$ac_cv_func_dlerror" != yes; then
  if test "$ac_cv_func_shl_load" != yes ||
     test "$ac_cv_func_shl_unload" != yes ||
     test "$ac_cv_func_shl_findsym" != yes; then
    dynamic=no
  elif test "x$dynamic" = xyes; then
    hpuxdynamic=yes
    DL_EXT="${DL_EXT=sl}"
    dnl autoheader won't allow us to define anything which isn't
    dnl going into a header, and we can't undefine anything, so
    dnl just define this anyway and rely on the later tests to
    dnl define DYNAMIC or not.
    AC_DEFINE(HPUX10DYNAMIC)dnl
  fi
fi

test -n "$GCC" && LDARG=-Wl,

AH_TEMPLATE([DLSYM_NEEDS_UNDERSCORE],
[Define to 1 if an underscore has to be prepended to dlsym() argument.])
AH_TEMPLATE([DYNAMIC_NAME_CLASH_OK],
[Define to 1 if multiple modules defining the same symbol are OK.])
if test "x$aixdynamic" = xyes; then
  DL_EXT="${DL_EXT=so}"
  DLLD="${DLLD=$CC}"
  zsh_cv_func_dlsym_needs_underscore=no
  if test -n "$GCC"; then
    DLLDFLAGS=${DLLDFLAGS=-shared}
  else
    DLLDFLAGS=${DLLDFLAGS=-bM:SRE}
  fi
  DLLDFLAGS=${DLLDFLAGS=}
  EXTRA_LDFLAGS=${EXTRA_LDFLAGS=}
  EXPOPT=${LDARG}-bE:
  IMPOPT=${LDARG}-bI:
  zsh_cv_sys_dynamic_clash_ok="${zsh_cv_sys_dynamic_clash_ok=yes}"
  zsh_cv_sys_dynamic_rtld_global="${zsh_cv_sys_dynamic_rtld_global=yes}"
  zsh_cv_sys_dynamic_execsyms="${zsh_cv_sys_dynamic_execsyms=yes}"
  zsh_cv_sys_dynamic_strip_exe="${zsh_cv_sys_dynamic_strip_exe=yes}"
  zsh_cv_sys_dynamic_strip_lib="${zsh_cv_sys_dynamic_strip_lib=yes}"
  zsh_cv_shared_environ="${zsh_cv_shared_environ=yes}"
elif test "$host_os" = cygwin; then
  DL_EXT="${DL_EXT=dll}"
##DLLD="${DLLD=dllwrap}"
  DLLD="${DLLD=$CC}"
##DLLDFLAGS="${DLLDFLAGS=--export-all-symbols}"
  DLLDFLAGS=${DLLDFLAGS=-shared -Wl,--export-all-symbols}
  zsh_cv_func_dlsym_needs_underscore=no
  DLLDFLAGS=${DLLDFLAGS=}
  EXTRA_LDFLAGS=${EXTRA_LDFLAGS=}
  zsh_cv_sys_dynamic_clash_ok="${zsh_cv_sys_dynamic_clash_ok=no}"
  zsh_cv_sys_dynamic_rtld_global="${zsh_cv_sys_dynamic_rtld_global=yes}"
  zsh_cv_sys_dynamic_execsyms="${zsh_cv_sys_dynamic_execsyms=no}"
  zsh_cv_sys_dynamic_strip_exe="${zsh_cv_sys_dynamic_strip_exe=yes}"
  zsh_cv_sys_dynamic_strip_lib="${zsh_cv_sys_dynamic_strip_lib=yes}"
  #
  # THAT SUCKS! and must be changed
  #
  zsh_cv_shared_environ="${zsh_cv_shared_environ=yes}"
  LINKMODS=LINKMODS
  MOD_EXPORT="__attribute__((__dllexport__))"
  MOD_IMPORT_VARIABLE="__attribute__((__dllimport__))"
  MOD_IMPORT_FUNCTION=
elif test "x$dynamic" = xyes; then
  AC_CACHE_CHECK(if your system uses ELF binaries,
   zsh_cv_sys_elf,
   [AC_RUN_IFELSE([AC_LANG_SOURCE([[/* Test for whether ELF binaries are produced */
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
	char b[4];
	int i = open(argv[0],O_RDONLY);
	if(i == -1) 
		return(1); /* fail */
	if(read(i,b,4)==4 && b[0]==127 && b[1]=='E' && b[2]=='L' && b[3]=='F')
		return(0); /* succeed (yes, it's ELF) */
	else
		return(1); /* fail */
}]])],[zsh_cv_sys_elf=yes],[zsh_cv_sys_elf=no],[zsh_cv_sys_elf=yes])])

  # We use [0-9]* in case statements, so need to change quoting
  changequote(, )

  DL_EXT="${DL_EXT=so}"
  if test x$zsh_cv_sys_elf = xyes; then
    case "$host" in
      mips-sni-sysv4*)
        # Forcibly set ld to native compiler to avoid obscure GCC problems
	DLLD="${DLLD=/usr/ccs/bin/cc}"
	DLLDARG="${LDARG}"
      ;;
      * )
	DLLD="${DLLD=$CC}"
	DLLDARG="${LDARG}"
      ;;
    esac
  else
    case "$host" in
      *openbsd*)
	case "$host_os" in
	  openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
	    DLLD="${DLLD=ld}"
	  ;;
	  *)
	    DLLD="${DLLD=$CC}"
	  ;;
	esac
	DLLDARG="${LDARG}"
      ;;
      *darwin*)
        DLLD="${DLLD=$CC}"
        DLLDARG=""
      ;;
      *interix*)
        DLLD="${DLLD=$CC}"
        DLLDARG=""
      ;;
      * )
	DLLD="${DLLD=ld}"
	DLLDARG=""
      ;;
    esac
  fi
  if test -n "$GCC"; then
    case "$host_os" in
      hpux*)   DLLDFLAGS="${DLLDFLAGS=-shared}" ;;
      darwin*) DLCFLAGS="${DLCFLAGS=-fno-common}" ;;
      interix*) DLCFLAGS="${DLCFLAGS=}" ;;
      *)       DLCFLAGS="${DLCFLAGS=-fPIC}" ;;
    esac
  else
    case "$host_os" in
      hpux*)
        DLCFLAGS="${DLCFLAGS=+z}"
        DLLDFLAGS="${DLLDFLAGS=-b}"
      ;;
      sunos*)                DLCFLAGS="${DLCFLAGS=-pic}" ;;
      solaris*|sysv4*|esix*) DLCFLAGS="${DLCFLAGS=-KPIC}" ;;
    esac
  fi
  case "$host_os" in
    osf*) DLLDFLAGS="${DLLDFLAGS=-shared -expect_unresolved '*'}" ;;
    *freebsd*|*netbsd*|linux*|irix*|gnu*|interix*|dragonfly*|haiku*) DLLDFLAGS="${DLLDFLAGS=-shared}" ;;
    sunos*)       DLLDFLAGS="${DLLDFLAGS=-assert nodefinitions}" ;;
    sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G $ldflags}" ;;
    aix*)         DLLDFLAGS="${DLLDFLAGS=-G -bexpall -lc}" ;;
    solaris*|sysv4*|esix*) DLLDFLAGS="${DLLDFLAGS=-G}" ;;
    darwin*)      DLLDFLAGS="${DLLDFLAGS=-bundle -flat_namespace -undefined suppress}" ;;
    beos*) DLLDFLAGS="${DLLDFLAGS=-nostart}" ;;
    openbsd*)
      if test x$zsh_cv_sys_elf = xyes; then
	DLLDFLAGS="${DLLDFLAGS=-shared -fPIC}"
      else
	case "$host_os" in
	  openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*)
	   DLLDFLAGS="${DLLDFLAGS=-Bshareable}"
	  ;;
	  *)
	    DLLDFLAGS="${DLLDFLAGS=-shared -fPIC}"
	  ;;
	esac
      fi
    ;;
  esac
  case "$host" in
    *-hpux*)  EXTRA_LDFLAGS="${EXTRA_LDFLAGS=-Wl,-E}" ;;
    *openbsd*)
       if test x$zsh_cv_sys_elf = xyes; then
	 EXTRA_LDFLAGS="${EXTRA_LDFLAGS=-Wl,-E}"
       fi
    ;;
    mips-sni-sysv4)
      #
      # unfortunately, we have different compilers
      # that need different flags
      #
      if test -n "$GCC"; then
        sni_cc_version=GCC
      else
        sni_cc_version=`$CC -V 2>&1 | head -1`
      fi
      case "$sni_cc_version" in
        *CDS*|GCC )
         EXTRA_LDFLAGS="${EXTRA_LDFLAGS=-Wl,-Blargedynsym}"
       ;;
       * )
         EXTRA_LDFLAGS="${EXTRA_LDFLAGS=-LD-Blargedynsym}"
       ;;
      esac
    ;;
    *-beos*)
      # gcc on BeOS doesn't like -rdynamic...
      EXTRA_LDFLAGS="${EXTRA_LDFLAGS= }"
      # also, dlopen() at least in Zeta respects $LIBRARY_PATH, so needs %A added to it.
      export LIBRARY_PATH="$LIBRARY_PATH:%A/"
    ;;
    *-haiku*)
      # 
    ;;
  esac

  # Done with our shell code, so restore autotools quoting
  changequote([, ])

AC_CACHE_CHECK(if we can use -rdynamic, zsh_cv_rdynamic_available,
old_LDFLAGS="$LDFLAGS"
LDFLAGS="$LDFLAGS -rdynamic"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],[zsh_cv_rdynamic_available=yes
EXTRA_LDFLAGS="${EXTRA_LDFLAGS=-rdynamic}"],[zsh_cvs_rdynamic_available=no])
LDFLAGS="$old_LDFLAGS")
  AC_CACHE_CHECK(if your dlsym() needs a leading underscore,
   zsh_cv_func_dlsym_needs_underscore,
   [echo failed >conftestval && cat >conftest.c <<EOM
void fred () { }
EOM
    AC_TRY_COMMAND($CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest.c 1>&AS_MESSAGE_LOG_FD) &&
    AC_TRY_COMMAND($DLLD $LDFLAGS $DLLDFLAGS -o conftest.$DL_EXT conftest.o 1>&AS_MESSAGE_LOG_FD) &&
    AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#ifdef HPUX10DYNAMIC
#include <dl.h>
#define RTLD_LAZY BIND_DEFERRED
#define RTLD_GLOBAL DYNAMIC_PATH

char *zsh_gl_sym_addr ;

#define dlopen(file,mode) (void *)shl_load((file), (mode), (long) 0)
#define dlclose(handle) shl_unload((shl_t)(handle))
#define dlsym(handle,name) (zsh_gl_sym_addr=0,shl_findsym((shl_t *)&(handle),name,TYPE_UNDEFINED,&zsh_gl_sym_addr), (void *)zsh_gl_sym_addr)
#define dlerror() 0
#else
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#else
#include <sys/types.h>
#include <nlist.h>
#include <link.h>
#endif
#endif
#ifndef RTLD_LAZY
#define RTLD_LAZY 1
#endif

extern int fred() ;

int main()
{
    void * handle ;
    void * symbol ;
    FILE *f=fopen("conftestval", "w");
    if (!f) return(1);
    handle = dlopen("./conftest.$DL_EXT", RTLD_LAZY) ;
    if (handle == NULL) {
        fprintf (f, "dlopen failed") ;
            return(1);
    }
    symbol = dlsym(handle, "fred") ;
    if (symbol == NULL) {
                /* try putting a leading underscore */
        symbol = dlsym(handle, "_fred") ;
        if (symbol == NULL) {
            fprintf (f, "dlsym failed") ;
                return(1);
                }
        fprintf (f, "yes") ;
    }
    else
        fprintf (f, "no") ;
    return(0);
}]])],[zsh_cv_func_dlsym_needs_underscore=`cat conftestval`],[zsh_cv_func_dlsym_needs_underscore=failed
    dynamic=no],[zsh_cv_func_dlsym_needs_underscore=no])])
  if test "x$zsh_cv_func_dlsym_needs_underscore" = xyes; then
    AC_DEFINE(DLSYM_NEEDS_UNDERSCORE)
  elif test "x$zsh_cv_func_dlsym_needs_underscore" != xno; then
    dnl Do not cache failed value
    unset zsh_cv_func_dlsym_needs_underscore
  fi
fi

if test "x$dynamic" = xyes; then
  zsh_SHARED_VARIABLE([environ], [char **])
  test "$zsh_cv_shared_environ" = yes || dynamic=no
  if test "$ac_cv_func_tgetent" = yes; then
    zsh_SHARED_FUNCTION([tgetent])
  fi
  if test "$ac_cv_func_tigetstr" = yes; then
    zsh_SHARED_FUNCTION([tigetstr])
  fi
fi

if test "x$dynamic" = xyes; then
  zsh_SYS_DYNAMIC_CLASH
  zsh_SYS_DYNAMIC_GLOBAL
  RTLD_GLOBAL_OK=$zsh_cv_sys_dynamic_rtld_global
  zsh_SYS_DYNAMIC_EXECSYMS
  if test "$zsh_cv_sys_dynamic_execsyms" != yes; then
    L=L
  fi
  zsh_SYS_DYNAMIC_STRIP_EXE
  zsh_SYS_DYNAMIC_STRIP_LIB
  if $strip_exeldflags && test "$zsh_cv_sys_dynamic_strip_exe" = yes; then
    EXELDFLAGS="$EXELDFLAGS -s"
  fi
  if $strip_libldflags && test "$zsh_cv_sys_dynamic_strip_lib" = yes; then
    LIBLDFLAGS="$LIBLDFLAGS -s"
  fi
  if test "$host_os" = cygwin; then
    INSTLIB="install.cygwin-lib"
    UNINSTLIB="uninstall.cygwin-lib"
  fi
else
  $strip_exeldflags && EXELDFLAGS="$EXELDFLAGS -s"
  $strip_libldflags && LIBLDFLAGS="$LIBLDFLAGS -s"
  RTLD_GLOBAL_OK=no
fi

AH_TEMPLATE([DYNAMIC],
[Define to 1 if you want to use dynamically loaded modules.])
if test "x$dynamic" = xyes; then
  D=D
  AC_DEFINE(DYNAMIC)dnl
else
  D=N
fi

AH_TEMPLATE([AIXDYNAMIC],
[Define to 1 if you want to use dynamically loaded modules on AIX.])
if test "x$aixdynamic" = xyes; then
  E=E
  AC_DEFINE(AIXDYNAMIC)dnl
else
  E=N
fi

if test "x$zsh_cv_sys_dynamic_clash_ok" = xyes; then
  SHORTBOOTNAMES=yes
else
  SHORTBOOTNAMES=no
fi
AC_SUBST(SHORTBOOTNAMES)

AC_SUBST(INSTLIB)dnl
AC_SUBST(UNINSTLIB)dnl

if test "$host_os" = cygwin; then
  EXTRAZSHOBJS="$EXTRAZSHOBJS zsh.res.o"
fi

AC_DEFINE_UNQUOTED(DL_EXT, "$DL_EXT",
[The extension used for dynamically loaded modules.])dnl
AC_SUBST(D)dnl
AC_SUBST(DL_EXT)dnl
AC_SUBST(DLLD)dnl
AC_SUBST(DLCFLAGS)dnl
AC_SUBST(DLLDFLAGS)dnl
AC_SUBST(E)dnl
AC_SUBST(EXTRA_LDFLAGS)dnl
AC_SUBST(EXPOPT)dnl
AC_SUBST(IMPOPT)dnl
AC_SUBST(L)dnl
AC_SUBST(LINKMODS)dnl
AC_SUBST(MOD_EXPORT)dnl
AC_SUBST(MOD_IMPORT_VARIABLE)dnl
AC_SUBST(MOD_IMPORT_FUNCTION)dnl
AC_SUBST(EXTRAZSHOBJS)dnl

# Generate config.modules.  We look for *.mdd files in first and second
# level subdirectories.  Any existing line not containing 'auto=y' will be
# retained, provided the .mdd file itself was found.
CONFIG_MODULES=./config.modules
cat <<EOM > ${CONFIG_MODULES}.sh
srcdir="$srcdir"
dynamic="$dynamic"
CONFIG_MODULES="${CONFIG_MODULES}"
EOM
cat <<\EOM >> ${CONFIG_MODULES}.sh
echo "creating ${CONFIG_MODULES}"
userlist=" "
if test -f ${CONFIG_MODULES}; then
  userlist="`sed -e '/^#/d' -e '/auto=y/d' -e 's/ .*/ /' -e 's/^name=/ /' \
        ${CONFIG_MODULES}`"
  mv ${CONFIG_MODULES} ${CONFIG_MODULES}.old
else
  # Save testing for existence each time.
  echo > ${CONFIG_MODULES}.old
fi
(echo "# Edit this file to change the way modules are loaded."
echo "# The format is strict; do not break lines or add extra spaces."
echo "# Run \`make prep' if you change anything here after compiling"
echo "# (there is no need if you change this just after the first time"
echo "# you run \`configure')."
echo "#"
echo "# Values of \`link' are \`static', \`dynamic' or \`no' to compile the"
echo "# module into the shell, link it in at run time, or not use it at all."
echo "# In the final case, no attempt will be made to compile it."
echo "# Use \`static' or \`no' if you do not have dynamic loading."
echo "#"
echo "# Values of \`load' are \`yes' or \`no'; if yes, any builtins etc."
echo "# provided by the module will be autoloaded by the main shell"
echo "# (so long as \`link' is not set to \`no')."
echo "#"
echo "# Values of \`auto' are \`yes' or \`no'. configure sets the value to"
echo "# \`yes'.  If you set it by hand to \`no', the line will be retained"
echo "# when the file is regenerated in future."
echo "#"
echo "# Note that the \`functions' entry extends to the end of the line."
echo "# It should not be quoted; it is used verbatim to find files to install."
echo "#"
echo "# You will need to run \`config.status --recheck' if you add a new"
echo "# module."
echo "#"
echo "# You should not change the values for the pseudo-module zsh/main,"
echo "# which is the main shell (apart from the functions entry)."
EOM
dnl The autoconf macros are only available in configure, not
dnl config.status, and only change when configure is rerun.
dnl So we need to run the autoconf tests here and store the results.
dnl We then generate config.modules, preserving any user-generated
dnl information, from config.status.
for modfile in `cd ${srcdir}; echo */*.mdd */*/*.mdd`; do
  name=
  link=
  load=
  functions=
  result=
  . ${srcdir}/$modfile
  if test x$name != x && test x"$link" != x; then
    case "$link" in
      *\ *) eval "link=\`$link\`"
	    ;;
    esac
    case "${load}" in
      y*) load=" load=yes"
	  ;;
      *) load=" load=no"
	 ;;
    esac
    if test "x$functions" != x; then
      # N.B. no additional quotes
      f=" functions=$functions"
    else
      f=
    fi
    case "$link" in
      static) result="name=$name modfile=$modfile link=static auto=yes${load}$f"
	      ;;
      dynamic) if test x$dynamic != xno; then
		  result="name=$name modfile=$modfile link=dynamic\
 auto=yes${load}$f"
	       else
		 result="name=$name modfile=$modfile link=no\
 auto=yes load=no$f"
	       fi
	       ;;
      either) if test x$dynamic != xno; then
		result="name=$name modfile=$modfile link=dynamic\
 auto=yes${load}$f"
	      else
		result="name=$name modfile=$modfile link=static\
 auto=yes${load}$f"
	      fi
	      ;;
       *) result="name=$name modfile=$modfile link=no auto=yes load=no$f"
	  ;;
    esac
dnl $result is the default output for config.modules.  We generate
dnl code to check if we should use this.
cat <<EOM >> ${CONFIG_MODULES}.sh
case "\$userlist" in
  *" $name "*) grep "^name=$name " \${CONFIG_MODULES}.old;;
  *) echo "$result";;
esac
EOM
  fi
done
cat <<\EOM >> ${CONFIG_MODULES}.sh
) >${CONFIG_MODULES}
rm -f ${CONFIG_MODULES}.old
EOM

dnl AH_TOP replaces the code which used to appear at the top
dnl of acconfig.h.
AH_TOP([/***** begin user configuration section *****/

/* Define this to be the location of your password file */
#define PASSWD_FILE "/etc/passwd"

/* Define this if you use "suspended" instead of "stopped" */
#define USE_SUSPENDED 1
 
/* The default history buffer size in lines */
#define DEFAULT_HISTSIZE 30

/* The default editor for the fc builtin */
#define DEFAULT_FCEDIT "vi"

/* The default prefix for temporary files */
#define DEFAULT_TMPPREFIX "/tmp/zsh"

/***** end of user configuration section            *****/
/***** shouldn't have to change anything below here *****/

])

CLEAN_MK="${srcdir}/Config/clean.mk"
CONFIG_MK="${srcdir}/Config/config.mk"
dnl defs.mk is in the build tree, not the source tree
DEFS_MK="Config/defs.mk"
VERSION_MK="${srcdir}/Config/version.mk"

AC_SUBST_FILE(CLEAN_MK)dnl
AC_SUBST_FILE(CONFIG_MK)dnl
AC_SUBST_FILE(DEFS_MK)dnl
AC_SUBST_FILE(VERSION_MK)dnl

AC_CONFIG_FILES(Config/defs.mk Makefile Doc/Makefile Etc/Makefile \
Src/Makefile Test/Makefile)
AC_CONFIG_COMMANDS([config.modules], [. ./config.modules.sh])
AC_CONFIG_COMMANDS([stamp-h], [echo >stamp-h])

AC_OUTPUT

dnl Copy pre-built man pages and help files, for tarball out-of-tree builds.
for manpage in `cd ${srcdir} && echo Doc/*.1`; do
  if test x"$manpage" != x"Doc/*.1" && ! test -e "${manpage}"; then
    cp ${srcdir}/${manpage} ./Doc/
  fi
done
if ! test -e Doc/help.txt; then
  cp ${srcdir}/Doc/help.txt ./Doc/
fi
mkdir -p ./Doc/help
for helpfile in `cd ${srcdir} && echo Doc/help/*`; do
  if test x"$helpfile" != x"Doc/help/*" && ! test -e "${helpfile}"; then
    cp ${srcdir}/${helpfile} ./Doc/help/
  fi
done

eval "zshbin1=${bindir}"
eval "zshbin2=${zshbin1}"
eval "zshman1=${mandir}"
eval "zshman2=${zshman1}"
eval "zshinfo1=${infodir}"
eval "zshinfo2=${zshinfo1}"
eval "zshfndir1=${fndir}"
eval "zshfndir2=${zshfndir1}"

echo "
zsh configuration
-----------------
zsh version               : ${VERSION}
host operating system     : ${host_cpu}-${host_vendor}-${host_os}
source code location      : ${srcdir}
compiler                  : ${CC}
preprocessor flags        : ${CPPFLAGS}
executable compiler flags : ${CFLAGS}"
if test "x$dynamic" = xyes; then
  echo "\
module compiler flags     : ${CFLAGS} ${DLCFLAGS}"
fi
echo "\
executable linker flags   : ${LDFLAGS} ${EXELDFLAGS} ${EXTRA_LDFLAGS}"
if test "x$dynamic" = xyes; then
  echo "\
module linker flags       : ${LDFLAGS} ${LIBLDFLAGS} ${DLLDFLAGS}"
fi
echo "\
library flags             : ${LIBS}
installation basename     : ${tzsh_name}
binary install path       : ${zshbin2}
man page install path     : ${zshman2}
info install path         : ${zshinfo2}"
if test "$zshfndir2" != no; then
  echo "functions install path    : ${zshfndir2}"
fi
if test "x$additionalfpath" != x; then
  echo "additional fpath entries  : ${additionalfpath}"
fi
echo "See config.modules for installed modules and functions.
"

if test x$zsh_cv_c_unicode_support != xyes; then
  if test "x$zfuncs_absent" = x; then
    # The user opted out.
    AC_MSG_WARN([You have chosen to build without multibyte support.])
    AC_MSG_WARN([This configuration may not be suitable for production use. It is known to cause errors in 'make test'. We strongly recommend to re-run configure with --enable-multibyte.])
  else
    # Some requisite functions are missing.
    AC_MSG_WARN([Multibyte support cannot be enabled: some standard library functions are missing: $zfuncs_absent])
    AC_MSG_WARN([This configuration may not be suitable for production use. It is known to cause errors in 'make test'. If your system provides those functions, we recommend to re-run configure appropriately.])
    # If your system doesn't have those functions, consider patching the
    # test suite and sending the patch to zsh-workers@ for inclusion.
  fi
fi

exit 0