summaryrefslogtreecommitdiff
path: root/automake.in
blob: b7261a966aa9a045ea3cc127c3ed6305a2484855 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
#!@PERL@ -w
# -*- perl -*-
# @configure_input@

eval 'exec @PERL@ -S $0 ${1+"$@"}'
    if 0;

# automake - create Makefile.in from Makefile.am
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
# Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

# Originally written by David Mackenzie <djm@gnu.ai.mit.edu>.
# Perl reimplementation by Tom Tromey <tromey@cygnus.com>.

package Language;

BEGIN
{
  my $prefix = "@prefix@";
  my $perllibdir = $ENV{'perllibdir'} || "@datadir@/@PACKAGE@";
  unshift @INC, "$perllibdir";
}

use Automake::Struct;
struct ('ansi'    => '$',
	'autodep' => '$',
        'compile'  => '$',
        # Flag to require compilation without linking (-c).
        'compile_flag' => '$',
        'compiler'  => '$',
	'derived_autodep' => '$',
        'extensions'      => '@',
        'flags' => '$',
        'linker' => '$',
        'name'       => '$',
        # Flag to specify the output file (-o).
        'output_flag' => '$',
	# `pure' is `1' or `'.  A `pure' language is one where, if
	# all the files in a directory are of that language, then we
	# do not require the C compiler or any code to call it.
	'pure'   => '$',
        '_finish' => '$');


sub finish ($)
{
  my ($self) = @_;
  &{$self->_finish} ();
}


package Automake;

require 5.005;
use strict 'vars', 'subs';
use File::Basename;
use IO::File;

my $me = basename ($0);


## ----------- ##
## Constants.  ##
## ----------- ##

# Parameters set by configure.  Not to be changed.  NOTE: assign
# VERSION as string so that eg version 0.30 will print correctly.
my $VERSION = "@VERSION@";
my $PACKAGE = "@PACKAGE@";
my $prefix = "@prefix@";
my $am_dir = "@datadir@/@PACKAGE@/am";
my $pkgdata_dir = "@datadir@/@PACKAGE@";

# String constants.
my $IGNORE_PATTERN = '^##([^#].*)?$';
my $WHITE_PATTERN = '^\s*$';
my $COMMENT_PATTERN = '^#';
my $TARGET_PATTERN='[$a-zA-Z_.][-.a-zA-Z0-9_(){}/$]*';
my $RULE_PATTERN = "^($TARGET_PATTERN) *:([^=].*|)\$";
my $SUFFIX_RULE_PATTERN = '^\.([a-zA-Z0-9]+)\.([a-zA-Z0-9]+)$';
# Only recognize leading spaces, not leading tabs.  If we recognize
# leading tabs here then we need to make the reader smarter, because
# otherwise it will think rules like `foo=bar; \' are errors.
my $MACRO_PATTERN = '^ *([A-Za-z0-9_@]+)\s*([:+]?)=\s*(.*)$';
my $BOGUS_MACRO_PATTERN = '^ *([^ \t]*)\s*([:+]?)=\s*(.*)$';
# This pattern recognizes a Gnits version id and sets $1 if the
# release is an alpha release.  We also allow a suffix which can be
# used to extend the version number with a "fork" identifier.
my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?(-[A-Za-z0-9]+)?';
my $IF_PATTERN =          '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?$';
my $ELSE_PATTERN =   '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
my $ENDIF_PATTERN = '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
my $PATH_PATTERN='(\w|[/.-])+';
# This will pass through anything not of the prescribed form.
my $INCLUDE_PATTERN = ('^include\s+'
		       . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
		       . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
		       . '|([^/\$]' . $PATH_PATTERN. '))\s*(#.*)?$');

# Some regular expressions.  One reason to put them here is that it
# makes indentation work better in Emacs.
my $AC_CONFIG_AUX_DIR_PATTERN = 'AC_CONFIG_AUX_DIR\(([^)]+)\)';
my $AM_INIT_AUTOMAKE_PATTERN = 'AM_INIT_AUTOMAKE\([^,]*,([^,)]+)[,)]';
my $AM_PACKAGE_VERSION_PATTERN = '^\s*\[?([^]\s]+)\]?\s*$';
# Note that there is no AC_PATH_TOOL.  But we don't really care.
my $AC_CHECK_PATTERN = 'AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\(\[?(\w+)';
my $AM_MISSING_PATTERN = 'AM_MISSING_PROG\(\[?(\w+)';
# Just check for alphanumeric in AC_SUBST.  If you do AC_SUBST(5),
# then too bad.
my $AC_SUBST_PATTERN = 'AC_SUBST\(\[?(\w+)';
my $AM_CONDITIONAL_PATTERN = 'AM_CONDITIONAL\(\[?(\w+)';

# Constants to define the "strictness" level.
my $FOREIGN = 0;
my $GNU = 1;
my $GNITS = 2;

# Values for AC_CANONICAL_*
my $AC_CANONICAL_HOST = 1;
my $AC_CANONICAL_SYSTEM = 2;

# Files installed by libtoolize.
my @libtoolize_files = ('ltmain.sh', 'config.guess', 'config.sub');
# ltconfig appears here for compatibility with old versions of libtool.
my @libtoolize_sometimes = ('ltconfig', 'ltcf-c.sh', 'ltcf-cxx.sh',
			    'ltcf-gcj.sh');

# Commonly found files we look for and automatically include in
# DISTFILES.
my @common_files =
  (
   'README', 'THANKS', 'TODO', 'NEWS', 'COPYING', 'COPYING.LIB',
   'INSTALL', 'ABOUT-NLS', 'ChangeLog', 'configure.ac',
   'configure.in', 'configure', 'config.guess', 'config.sub',
   'AUTHORS', 'BACKLOG', 'ABOUT-GNU', 'libversion.in',
   'mdate-sh', 'mkinstalldirs', 'install-sh', 'texinfo.tex',
   'ansi2knr.c', 'ansi2knr.1', 'elisp-comp',
   # ltconfig appears here for compatibility with old versions
   # of libtool.
   'ylwrap', 'acinclude.m4', @libtoolize_files, @libtoolize_sometimes,
   'missing', 'depcomp', 'compile', 'py-compile'
  );

# Commonly used files we auto-include, but only sometimes.
my @common_sometimes =
  (
   'aclocal.m4', 'acconfig.h', 'config.h.top',
   'config.h.bot', 'stamp-h.in', 'stamp-vti'
  );

# Copyright on generated Makefile.ins.
my $gen_copyright = "\
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
";

# These constants are returned by lang_*_rewrite functions.
# LANG_SUBDIR means that the resulting object file should be in a
# subdir if the source file is.  In this case the file name cannot
# have `..' components.
my $LANG_IGNORE = 0;
my $LANG_PROCESS = 1;
my $LANG_SUBDIR = 2;

# Directories installed during 'install-exec' phase.
my %exec_dir_p =
  (
   'bin'	=> 1,
   'sbin'	=> 1,
   'libexec'	=> 1,
   'data'	=> 0,
   'sysconf'	=> 1,
   'localstate'	=> 1,
   'lib'	=> 1,
   'info'	=> 0,
   'man'	=> 0,
   'include'	=> 0,
   'oldinclude'	=> 0,
   'pkgdata'	=> 0,
   'pkglib'	=> 1,
   'pkginclude'	=> 0
  );

# Map from obsolete macros to hints for new macros.
# If you change this, change the corresponding list in aclocal.in.
# FIXME: should just put this into a single file.
my %obsolete_macros =
    (
     'AC_FEATURE_CTYPE'		=> "use `AC_HEADER_STDC'",
     'AC_FEATURE_ERRNO'		=> "add `strerror' to `AC_REPLACE_FUNCS(...)'",
     'AC_FEATURE_EXIT'		=> '',
     'AC_SYSTEM_HEADER'		=> '',

     # Note that we do not handle this one, because it is still run
     # from AM_CONFIG_HEADER.  So we deal with it specially in
     # &scan_autoconf_files.
     # 'AC_CONFIG_HEADER'	=> "use `AM_CONFIG_HEADER'",

     'fp_C_PROTOTYPES'		=> "use `AM_C_PROTOTYPES'",
     'fp_PROG_CC_STDC'		=> "use `AM_PROG_CC_STDC'",
     'fp_PROG_INSTALL'		=> "use `AC_PROG_INSTALL'",
     'fp_WITH_DMALLOC'		=> "use `AM_WITH_DMALLOC'",
     'fp_WITH_REGEX'		=> "use `AM_WITH_REGEX'",
     'gm_PROG_LIBTOOL'		=> "use `AM_PROG_LIBTOOL'",
     'jm_MAINTAINER_MODE'	=> "use `AM_MAINTAINER_MODE'",
     'md_TYPE_PTRDIFF_T'	=> "use `AM_TYPE_PTRDIFF_T'",
     'ud_PATH_LISPDIR'		=> "use `AM_PATH_LISPDIR'",
     'ud_GNU_GETTEXT'		=> "use `AM_GNU_GETTEXT'",

     # Now part of autoconf proper, under a different name.
     'AM_FUNC_FNMATCH'		=> "use `AC_FUNC_FNMATCH'",
     'fp_FUNC_FNMATCH'		=> "use `AC_FUNC_FNMATCH'",
     'AM_SANITY_CHECK_CC'	=> "automatically done by `AC_PROG_CC'",
     'AM_PROG_INSTALL'		=> "use `AC_PROG_INSTALL'",
     'AM_EXEEXT'		=> "use `AC_EXEEXT'",
     'AM_CYGWIN32'		=> "use `AC_CYGWIN'",
     'AM_MINGW32'		=> "use `AC_MINGW32'",
     'AM_FUNC_MKTIME'		=> "use `AC_FUNC_MKTIME'",

# These aren't quite obsolete.
#      'md_PATH_PROG',
     );

# Regexp to match the above macros.
my $obsolete_rx = '(\b' . join ('\b|\b', keys %obsolete_macros) . '\b)';



## ---------------------------------- ##
## Variables related to the options.  ##
## ---------------------------------- ##

# TRUE if we should always generate Makefile.in.
my $force_generation = 1;

# Strictness level as set on command line.
my $default_strictness = $GNU;

# Name of strictness level, as set on command line.
my $default_strictness_name = 'gnu';

# This is TRUE if automatic dependency generation code should be
# included in generated Makefile.in.
my $cmdline_use_dependencies = 1;

# TRUE if in verbose mode.
my $verbose = 0;

# This holds our (eventual) exit status.  We don't actually exit until
# we have processed all input files.
my $exit_status = 0;

# From the Perl manual.
my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');

# TRUE if missing standard files should be installed.
my $add_missing = 0;

# TRUE if we should copy missing files; otherwise symlink if possible.
my $copy_missing = 0;

# TRUE if we should always update files that we know about.
my $force_missing = 0;


## ---------------------------------------- ##
## Variables filled during files scanning.  ##
## ---------------------------------------- ##

# Name of the top autoconf input: `configure.ac' or `configure.in'.
my $configure_ac = '';

# Files found by scanning configure.ac for LIBOBJS.
my %libsources = ();

# True if AM_C_PROTOTYPES appears in configure.ac.
my $am_c_prototypes = 0;

# Names used in AC_CONFIG_HEADER call.  @config_fullnames holds the
# name which appears in AC_CONFIG_HEADER, colon and all.
# @config_names holds the file names.  @config_headers holds the '.in'
# files.  Ordinarily these are similar, but they can be different if
# the weird "NAME:FILE" syntax is used.
my @config_fullnames = ();
my @config_names = ();
my @config_headers = ();
# Line number at which AC_CONFIG_HEADER appears in configure.ac.
my $config_header_line = 0;

# Directory where output files go.  Actually, output files are
# relative to this directory.
my $output_directory = '.';

# List of Makefile.am's to process, and their corresponding outputs.
my @input_files = ();
my %output_files = ();

# Complete list of Makefile.am's that exist.
my @configure_input_files = ();

# List of files in AC_OUTPUT without Makefile.am, and their outputs.
my @other_input_files = ();
# Line number at which AC_OUTPUT seen.
my $ac_output_line = 0;

# List of directories to search for configure-required files.  This
# can be set by AC_CONFIG_AUX_DIR.
my @config_aux_path = ('.', '..', '../..');
my $config_aux_dir = '';

# Whether AM_GNU_GETTEXT has been seen in configure.ac.
my $seen_gettext = 0;
# Line number at which AM_GNU_GETTEXT seen.
my $ac_gettext_line = 0;

# Whether ALL_LINGUAS has been seen.
my $seen_linguas = '';
# The actual text.
my $all_linguas = '';
# Line number at which it appears.
my $all_linguas_line = 0;

# TRUE if AC_DECL_YYTEXT was seen.
my $seen_decl_yytext = 0;

# TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM).  The presence of
# AC_CHECK_TOOL also sets this.
my $seen_canonical = 0;

# TRUE if we've seen AC_PROG_LIBTOOL.
my $seen_libtool = 0;
my $libtool_line = 0;

# TRUE if we've seen AM_MAINTAINER_MODE.
my $seen_maint_mode = 0;

# Actual version we've seen.
my $package_version = '';

# Line number where we saw version definition.
my $package_version_line = 0;

# TRUE if we've seen AM_PATH_LISPDIR.
my $seen_lispdir = 0;

# TRUE if we've seen AM_CHECK_PYTHON.
my $seen_pythondir = 0;

# TRUE if we've seen AC_EXEEXT.
my $seen_exeext = 0;

# TRUE if we've seen AC_OBJEXT.
my $seen_objext = 0;

# TRUE if we've seen AC_ENABLE_MULTILIB.
my $seen_multilib = 0;

# TRUE if we've seen AM_PROG_CC_C_O
my $seen_cc_c_o = 0;

# TRUE if we've seen AM_INIT_AUTOMAKE.
my $seen_init_automake = 0;

# Hash table of discovered configure substitutions.  Keys are names,
# values are `FILE:LINE' strings which are used by error message
# generation.
my %configure_vars = ();

# This is used to keep track of which variable definitions we are
# scanning.  It is only used in certain limited ways, but it has to be
# global.  It is declared just for documentation purposes.
my %vars_scanned = ();

# Charsets used by maintainer and in distribution.  MAINT_CHARSET is
# handled in a funny way: if seen in the top-level Makefile.am, it is
# used for every directory which does not specify a different value.
# The rationale here is that some directories (eg gettext) might be
# distributions of other packages, and thus require their own charset
# info.  However, the DIST_CHARSET must be the same for the entire
# package; it can only be set at top-level.
# FIXME: this yields bugs when rebuilding.  What to do?  Always
# read (and sometimes discard) top-level Makefile.am?
my $maint_charset = '';
my $dist_charset = 'utf8';		# recode doesn't support this yet.

# TRUE if --cygnus seen.
my $cygnus_mode = 0;

# Hash table of AM_CONDITIONAL variables seen in configure.
my %configure_cond = ();

# This maps extensions onto language names.
my %extension_map = ();

# List of the DIST_COMMON files we discovered while reading
# configure.in
my $configure_dist_common = '';

# This maps languages names onto objects.
my %languages = ();

# List of targets we must always output.
# FIXME: Complete, and remove falsely required targets.
my %required_targets =
  (
   'all'          => 1,
   'dvi'	  => 1,
   'info'	  => 1,
   'install-info' => 1,
   'install'      => 1,
   'install-data' => 1,
   'install-exec' => 1,
   'uninstall'    => 1,

   # FIXME: Not required, temporary hacks.
   # Well, actually they are sort of required: the -recursive
   # targets will run them anyway...
   'dvi-am'          => 1,
   'info-am'         => 1,
   'install-data-am' => 1,
   'install-exec-am' => 1,
   'installcheck-am' => 1,
   'uninstall-am' => 1,

   'install-man' => 1,
  );



################################################################

## ------------------------------------------ ##
## Variables reset by &initialize_per_input.  ##
## ------------------------------------------ ##

# Basename and relative dir of the input file.
my $am_file_name;
my $am_relative_dir;

# Same but wrt Makefile.in.
my $in_file_name;
my $relative_dir;

# These two variables are used when generating each Makefile.in.
# They hold the Makefile.in until it is ready to be printed.
my $output_rules;
my $output_vars;
my $output_trailer;
my $output_all;
my $output_header;

# Suffixes found during a run.
my @suffixes;

# Handling the variables.
#
# For a $VAR:
# - $var_value{$VAR}{$COND} is its value associated to $COND,
# - $var_line{$VAR} is where it has been defined,
# - $var_comment{$VAR} are the comments associated to it.
# - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
# - $var_is_am{$VAR} is true if the variable is owned by Automake.
my %var_value;
my %var_line;
my %var_comment;
my %var_type;
my %var_is_am;

# This holds a 1 if a particular variable was examined.
my %content_seen;

# This holds the names which are targets.  These also appear in
# %contents.
my %targets;

# Same as %VAR_VALUE, but for targets.
my %target_conditional;

# This is the conditional stack.
my @cond_stack;

# This holds the set of included files.
my @include_stack;

# This holds a list of directories which we must create at `dist'
# time.  This is used in some strange scenarios involving weird
# AC_OUTPUT commands.
my %dist_dirs;

# List of dependencies for the obvious targets.
my @all;
my @check;
my @check_tests;

# Holds the dependencies of targets which dependencies are factored.
# Typically, `.PHONY' will appear in plenty of *.am files, but must
# be output once.  Arguably all pure dependencies could be subject
# to this factorization, but it is not unpleasant to have paragraphs
# in Makefile: keeping related stuff altogether.
my %dependencies;

# Holds the factored actions.  Tied to %DEPENDENCIES, i.e., filled
# only when keys exists in %DEPENDENCIES.
my %actions;

# A list of files deleted by `maintainer-clean'.
my @maintainer_clean_files;

# These are pretty obvious, too.  They are used to define the
# SOURCES and OBJECTS variables.
my @sources;
my @objects;
# Sources which go in the distribution.
my @dist_sources;

# This hash maps object file names onto their corresponding source
# file names.  This is used to ensure that each object is created
# by a single source file.
my %object_map;

# This keeps track of the directories for which we've already
# created `.dirstamp' code.
my %directory_map;

# All .P files.
my %dep_files;

# Strictness levels.
my $strictness;
my $strictness_name;

# Options from AUTOMAKE_OPTIONS.
my %options;

# Whether or not dependencies are handled.  Can be further changed
# in handle_options.
my $use_dependencies;

# Per Makefile.am.
my $local_maint_charset;

# All yacc and lex source filenames for this directory.  Use
# filenames instead of raw count so that multiple instances are
# counted correctly (eg one yacc file can appear in multiple
# programs without harm).
my %yacc_sources;
my %lex_sources;

# This is a list of all targets to run during "make dist".
my @dist_targets;

# Keys in this hash are the basenames of files which must depend
# on ansi2knr.
my %de_ansi_files;

# This maps the source extension of a suffix rule to its
# corresponding output extension.
my %suffix_rules;

# This is the name of the redirect `all' target to use.
my $all_target;

# This keeps track of which extensions we've seen (that we care
# about).
my %extension_seen;

# This is random scratch space for the language finish functions.
# Don't randomly overwrite it; examine other uses of keys first.
my %language_scratch;

# We keep track of which objects need special (per-executable)
# handling on a per-language basis.
my %lang_specific_files;

# This is set when `handle_dist' has finished.  Once this happens,
# we should no longer push on dist_common.
my $handle_dist_run;

# True if we need `LINK' defined.  This is a hack.
my $need_link;

# This is the list of such variables to output.
# FIXME: Might be useless actually.
my @var_list;

# Was get_object_extension run?
# FIXME: This is a hack. a better switch should be found.
my $get_object_extension_was_run;


## --------------------------------- ##
## Forward subroutine declarations.  ##
## --------------------------------- ##
sub register_language ($%);
sub file_contents_internal ($%);


# &initialize_per_input ()
# ------------------------
# (Re)-Initialize per-Makefile.am variables.
sub initialize_per_input ()
{
    $am_file_name = '';
    $am_relative_dir = '';

    $in_file_name = '';
    $relative_dir = '';

    $output_rules = '';
    $output_vars = '';
    $output_trailer = '';
    $output_all = '';
    $output_header = '';

    @suffixes = ();

    %var_value = ();
    %var_line = ();
    %var_comment = ();
    %var_type = ();
    %var_is_am = ();

    %content_seen = ();

    %targets = ();

    %target_conditional = ();

    @cond_stack = ();

    @include_stack = ();

    $relative_dir = '';

    $am_relative_dir = '';

    %dist_dirs = ();

    @all = ();
    @check = ();
    @check_tests = ();

    %dependencies =
      (
       # Texinfoing.
       'dvi'      => [],
       'dvi-am'   => [],
       'info'     => [],
       'info-am'  => [],

       # Installing/uninstalling.
       'install-data-am'      => [],
       'install-exec-am'      => [],
       'uninstall-am'         => [],

       'install-man'	      => [],
       'uninstall-man'	      => [],

       'install-info'         => [],
       'install-info-am'      => [],
       'uninstall-info'       => [],

       'installcheck-am'      => [],

       # Cleaning.
       'clean-am'             => [],
       'mostlyclean-am'       => [],
       'maintainer-clean-am'  => [],
       'distclean-am'         => [],
       'clean'                => [],
       'mostlyclean'          => [],
       'maintainer-clean'     => [],
       'distclean'            => [],

       # Tarballing.
       'dist-all'             => [],

       # Phoning.
       '.PHONY'               => []
      );
    %actions = ();

    @maintainer_clean_files = ();

    @sources = ();
    @objects = ();
    @dist_sources = ();

    %object_map = ();

    %directory_map = ();

    %dep_files = ();

    $strictness = $default_strictness;
    $strictness_name = $default_strictness_name;

    %options = ();

    $use_dependencies = $cmdline_use_dependencies;

    $local_maint_charset = $maint_charset;

    %yacc_sources = ();
    %lex_sources = ();

    @dist_targets = ();

    %de_ansi_files = ();

    %suffix_rules = ();

    $all_target = '';

    %extension_seen = ();

    %language_scratch = ();

    %lang_specific_files = ();

    $handle_dist_run = 0;

    $need_link = 0;

    @var_list = ();

    $get_object_extension_was_run = 0;
}


################################################################

# Initialize our list of languages that are internally supported.
register_language ('name' => 'c',
		   'ansi' => 1,
		   'autodep' => '',
		   'flags' => 'CFLAGS',
		   'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
		   'compiler' => 'COMPILE',
		   'compile_flag' => '-c',
		   'extensions' => ['c'],
		   '_finish' => \&lang_c_finish);
register_language ('name' => 'cxx',
		   'linker' => 'CXXLINK',
		   'autodep' => 'CXX',
		   'flags' => 'CXXFLAGS',
		    'compile' => '$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)',
		   'compiler' => 'CXXCOMPILE',
		   'compile_flag' => '-c',
		   'output_flag' => '-o',
		   'pure' => 1,
		   'extensions' => ['c++', 'cc', 'cpp', 'cxx', 'C'],
		   '_finish' => \&lang_cxx_finish);
register_language ('name' => 'objc',
		   'linker' => 'OBJCLINK',
		   'autodep' => 'OBJC',
		   'flags' => 'OBJCFLAGS',
		   'compile' => '$(OBJC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCFLAGS) $(OBJCFLAGS)',
		   'compiler' => 'OBJCCOMPILE',
		   'compile_flag' => '-c',
		   'output_flag' => '-o',
		   'pure' => 1,
		   'extensions' => ['m'],
		   '_finish' => \&lang_objc_finish);
register_language ('name' => 'header',
		   'extensions' => ['h', 'H', 'hxx', 'h++', 'hh', 'hpp', 'inc'],
		   # Nothing to do.
		   '_finish' => sub { });
# For now, yacc and lex can't be handled on a per-exe basis.
register_language ('name' => 'yacc',
		   'ansi' => 1,
		   'derived_autodep' => 'yes',
		   'extensions' => ['y'],
		   '_finish' => \&lang_yacc_finish);
register_language ('name' => 'yaccxx',
		   'linker' => 'CXXLINK',
		   'derived_autodep' => 'yes',
		   'extensions' => ['y++', 'yy', 'yxx', 'ypp'],
		    '_finish' => \&lang_yacc_finish);
register_language ('name' => 'lex',
		   'ansi' => 1,
		   'derived_autodep' => 'yes',
		   'extensions' => ['l'],
		   '_finish' => \&lang_lex_finish);
register_language ('name' => 'lexxx',
		   'linker' => 'CXXLINK',
		   'derived_autodep' => 'yes',
		   'extensions' => ['l++', 'll', 'lxx', 'lpp'],
		   '_finish' => \&lang_lex_finish);
register_language ('name' => 'asm',
		   'flags' => 'CFLAGS',
		   # FIXME: asmflags?
		   'compile' => '$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)',
		   # FIXME: a different compiler?
		   'compiler' => 'COMPILE',
		   'compile_flag' => '-c',
		   'extensions' => ['s', 'S'],
		   # We need the C code for assembly.
		   '_finish' => \&lang_c_finish);

register_language ('name' => 'f77',
		   'linker' => 'F77LINK',
		   'flags' => 'FFLAGS',
		   'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS)',
		   'compiler' => 'F77COMPILE',
		   'compile_flag' => '-c',
		   'output_flag' => '-o',
		   'pure' => 1,
		   'extensions' => ['f', 'for', 'f90'],
		   '_finish' => \&lang_f77_finish);
register_language ('name' => 'ppf77',
		   'linker' => 'F77LINK',
		   'flags' => 'FFLAGS',
		   'compile' => '$(F77) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)',
		   'compiler' => 'PPF77COMPILE',
		   'compile_flag' => '-c',
		   'output_flag' => '-o',
		   'pure' => 1,
		   'extensions' => ['F'],
		    '_finish' => \&lang_ppf77_finish);
register_language ('name' => 'ratfor',
		   'linker' => 'F77LINK',
		    'flags' => 'RFLAGS',
		   # FIXME also FFLAGS.
		   'compile' => '$(F77) $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)',
		   'compiler' => 'RCOMPILE',
		   'compile_flag' => '-c',
		   'output_flag' => '-o',
		   'pure' => 1,
		   'extensions' => ['r'],
		   '_finish' => \&lang_ratfor_finish);
# FIXME: for now we can't do dependency tracking for Java.
# autodep=GCJ
register_language ('name' => 'java',
		   'linker' => 'GCJLINK',
		   'flags' => 'GCJFLAGS',
		   'compile' => '$(GCJ) $(AM_GCJFLAGS) $(GCJFLAGS)',
		   'compiler' => 'GCJCOMPILE',
		   'compile_flag' => '-c',
		   'output_flag' => '-o',
		   'pure' => 1,
		   'extensions' => ['java', 'class', 'zip', 'jar'],
		   '_finish' => \&lang_java_finish);

################################################################

# Parse command line.
&parse_arguments;

# Do configure.ac scan only once.
&scan_autoconf_files;

die "$me: no `Makefile.am' found or specified\n"
    if ! @input_files;

# Now do all the work on each file.
# This guy must be local otherwise it's private to the loop.
use vars '$am_file';
local $am_file;
foreach $am_file (@input_files)
{
    if (! -f ($am_file . '.am'))
    {
	&am_error ("`" . $am_file . ".am' does not exist");
    }
    else
    {
 	&generate_makefile ($output_files{$am_file}, $am_file);
    }
}

exit $exit_status;

# FIXME: This should be `my'ed next to its subs.
use vars '%require_file_found';

################################################################

# prog_error (@PRINT-ME)
# ----------------------
# Signal a programming error, display PRINT-ME, and exit 1.
sub prog_error (@)
{
    print STDERR "$me: programming error: @_\n";
    exit 1;
}


# @RES
# uniq (@LIST)
# ------------
# Return LIST with no duplicates.
sub uniq (@)
{
   my @res = ();
   my %seen = ();
   foreach my $item (@_)
     {
       if (! defined $seen{$item})
	 {
	   $seen{$item} = 1;
	   push (@res, $item);
	 }
     }
   return @res;
}


################################################################


# $BACKPATH
# &backname ($REL-DIR)
# --------------------
# If I `cd $REL-DIR', then to come back, I should `cd $BACKPATH'.
# For instance `src/foo' => `../..'.
# Works with non strictly increasing paths, i.e., `src/../lib' => `..'.
sub backname ($)
{
    my ($file) = @_;
    my @res;
    foreach (split (/\//, $file))
    {
	next if $_ eq '.' || $_ eq '';
	if ($_ eq '..')
	{
	    pop @res;
	}
	else
	{
	    push (@res, '..');
	}
    }
    return join ('/', @res) || '.';
}

################################################################

# Parse command line.
sub parse_arguments ()
{
    # Start off as gnu.
    &set_strictness ('gnu');

    use Getopt::Long;
    Getopt::Long::config ("bundling");
    Getopt::Long::GetOptions
      (
       'version' 	=> \&version,
       'help'	 	=> \&usage,
       'amdir:s' 	=> \$am_dir,
       'gnu' 		=> sub { &set_strictness ('gnu'); },
       'gnits' 		=> sub { &set_strictness ('gnits'); },
       'cygnus' 	=> \$cygnus_mode,
       'foreign' 	=> sub { &set_strictness ('foreign'); },
       'include-deps' 	=> sub { $cmdline_use_dependencies = 1; },
       'i|ignore-deps' 	=> sub { $cmdline_use_dependencies = 0; },
       'no-force' 	=> sub { $force_generation = 0; },
       'f|force-missing'=> \$force_missing,
       'o|output-dir:s'	=> \$output_directory,
       'a|add-missing' 	=> \$add_missing,
       'c|copy' 	=> \$copy_missing,
       'v|verbose' 	=> \$verbose,
       'Werror'         => sub { $SIG{"__WARN__"} = sub { die $_[0] } },
       'Wno-error'      => sub { $SIG{"__WARN__"} = 'DEFAULT' }
      )
	or exit 1;

    foreach my $arg (@ARGV)
    {
      # Handle $local:$input syntax.  Note that we only examine the
      # first ":" file to see if it is automake input; the rest are
      # just taken verbatim.  We still keep all the files around for
      # dependency checking, however.
      my ($local, $input, @rest) = split (/:/, $arg);
      if (! $input)
	{
	  $input = $local;
	}
      else
	{
	  # Strip .in; later on .am is tacked on.  That is how the
	  # automake input file is found.  Maybe not the best way, but
	  # it is easy to explain.
	  $input =~ s/\.in$//
	    or die "$me: invalid input file name `$arg'\n.";
	}
      push (@input_files, $input);
      $output_files{$input} = join (':', ($local, @rest));
    }

    # Take global strictness from whatever we currently have set.
    $default_strictness = $strictness;
    $default_strictness_name = $strictness_name;
}

################################################################

# Generate a Makefile.in given the name of the corresponding Makefile and
# the name of the file output by config.status.
sub generate_makefile
{
    my ($output, $makefile) = @_;

    # Reset all the Makefile.am related variables.
    &initialize_per_input;

    # Name of input file ("Makefile.am") and output file
    # ("Makefile.in").  These have no directory components.
    $am_file_name = basename ($makefile) . '.am';
    $in_file_name = basename ($makefile) . '.in';

    # $OUTPUT is encoded.  If it contains a ":" then the first element
    # is the real output file, and all remaining elements are input
    # files.  We don't scan or otherwise deal with these input file,
    # other than to mark them as dependencies.  See
    # &scan_autoconf_files for details.
    my (@secondary_inputs);
    ($output, @secondary_inputs) = split (/:/, $output);

    $relative_dir = dirname ($output);
    $am_relative_dir = dirname ($makefile);

    &read_main_am_file ($makefile . '.am');
    if (&handle_options)
    {
	# Fatal error.  Just return, so we can continue with next file.
	return;
    }

    # There are a few install-related variables that you should not define.
    foreach my $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
    {
	if (&variable_defined ($var) && !$var_is_am{$var})
	{
	    &am_line_error ($var, "`$var' should not be defined");
	}
    }

    # At the toplevel directory, we might need config.guess, config.sub
    # or libtool scripts (ltconfig and ltmain.sh).
    if ($relative_dir eq '.')
    {
 	# libtool requires some files.
 	&require_conf_file_with_conf_line ($libtool_line, $FOREIGN,
 					   @libtoolize_files)
	    if $seen_libtool;

        # AC_CANONICAL_HOST and AC_CANONICAL_SYSTEM need config.guess and
        # config.sub.
        &require_config_file ($FOREIGN, 'config.guess', 'config.sub')
	    if $seen_canonical;
    }

    # We still need Makefile.in here, because sometimes the `dist'
    # target doesn't re-run automake.
    if ($am_relative_dir eq $relative_dir)
    {
	# Only distribute the files if they are in the same subdir as
	# the generated makefile.
	&push_dist_common ($in_file_name, $am_file_name);
    }

    push (@sources, '$(SOURCES)')
	if &variable_defined ('SOURCES');
    push (@objects, '$(OBJECTS)')
	if &variable_defined ('OBJECTS');

    # If OBJEXT/EXEEXT were not set in configure.in, do it, it
    # simplifies our task, and anyway starting with Autoconf 2.50, it
    # will always be defined, and this code will be dead.
    $output_vars .= "EXEEXT =\n"
      unless $seen_exeext;
    $output_vars .= "OBJEXT = o\n"
      unless $seen_objext;

    # Must do this after reading .am file.  See read_main_am_file to
    # understand weird tricks we play there with variables.
    &define_variable ('subdir', $relative_dir);

    # Check first, because we might modify some state.
    &check_cygnus;
    &check_gnu_standards;
    &check_gnits_standards;

    &handle_configure ($output, $makefile, @secondary_inputs);
    &handle_gettext;
    &handle_libraries;
    &handle_ltlibraries;
    &handle_programs;
    &handle_scripts;

    # This must be run after all the sources are scanned.
    &handle_languages;
    &handle_compile;

    # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
    # on this (but currently does).
    macro_define ('SOURCES', 1, '', 'TRUE',
		     join (' ', @sources), 'internal');
    macro_define ('OBJECTS', 1, '', 'TRUE',
		     join (' ', @objects), 'internal');
    &define_pretty_variable ('DIST_SOURCES', '', @dist_sources);

    &handle_multilib;
    &handle_texinfo;
    &handle_emacs_lisp;
    &handle_python;
    &handle_java;
    &handle_man_pages;
    &handle_data;
    &handle_headers;
    &handle_subdirs;
    &handle_tags;
    &handle_minor_options;
    &handle_tests;

    # This must come after most other rules.
    &handle_dist ($makefile);

    &handle_footer;
    &do_check_merge_target;
    &handle_all ($output);

    # FIXME: Gross!
    if (&variable_defined('lib_LTLIBRARIES') &&
	&variable_defined('bin_PROGRAMS'))
    {
	$output_rules .= "install-binPROGRAMS: install-libLTLIBRARIES\n\n";
    }

    &handle_installdirs;
    &handle_clean;
    &handle_factored_dependencies;

    &check_typos;

    if (! -d ($output_directory . '/' . $am_relative_dir))
    {
	mkdir ($output_directory . '/' . $am_relative_dir, 0755);
    }

    my ($out_file) = $output_directory . '/' . $makefile . ".in";
    if (! $force_generation && -e $out_file)
    {
	my ($am_time) = (stat ($makefile . '.am'))[9];
	my ($in_time) = (stat ($out_file))[9];
	# FIXME: should cache these times.
	my ($conf_time) = (stat ($configure_ac))[9];
	# FIXME: how to do unsigned comparison?
	if ($am_time < $in_time || $am_time < $conf_time)
	{
	    # No need to update.
	    return;
	}
	if (-f 'aclocal.m4')
	{
	    my ($acl_time) = (stat _)[9];
	    return if ($am_time < $acl_time);
	}
    }

    my $gm_file = new IO::File "> $out_file";
    if (! $gm_file)
    {
	warn "$me: ${am_file}.in: cannot write: $!\n";
	$exit_status = 1;
	return;
    }
    print "$me: creating ", $makefile, ".in\n" if $verbose;

    # In case we're running under MSWindows, don't write with CRLF
    # (as it causes problems for the dependency-file extraction in
    # AM_OUTPUT_DEPENDENCY_COMMANDS).
    binmode $gm_file;

    print $gm_file $output_vars;
    # We make sure that `all:' is the first target.
    print $gm_file $output_all;
    print $gm_file $output_header;
    print $gm_file $output_rules;
    print $gm_file $output_trailer;

    if (! $gm_file->close)
      {
	warn "$me: $am_file.in: cannot close: $!\n";
	$exit_status = 1;
	return;
      }
}

################################################################

# Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
sub handle_options
{
    if (&variable_defined ('AUTOMAKE_OPTIONS'))
    {
	foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS', ''))
	{
	    $options{$_} = 1;
	    if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
	    {
		&set_strictness ($_);
	    }
	    elsif ($_ eq 'cygnus')
	    {
		$cygnus_mode = 1;
	    }
	    elsif (/ansi2knr/)
	    {
		# An option like "../lib/ansi2knr" is allowed.  With
		# no path prefix, we assume the required programs are
		# in this directory.  We save the actual option for
		# later.
		$options{'ansi2knr'} = $_;
	    }
	    elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
		   || $_ eq 'dist-shar' || $_ eq 'dist-zip'
		   || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
		   || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
		   || $_ eq 'readme-alpha' || $_ eq 'check-news'
		   || $_ eq 'subdir-objects' || $_ eq 'nostdinc')
	    {
		# Explicitly recognize these.
	    }
	    elsif ($_ eq 'no-dependencies')
	    {
		$use_dependencies = 0;
	    }
	    elsif (/(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/)
	    {
		# Got a version number.

		my ($rmajor, $rminor, $ralpha, $rfork) = ($1, $2, $3, $4);

		&prog_error ("version is incorrect: $VERSION")
		  if $VERSION !~ /(\d+)\.(\d+)([a-z]?)(-[A-Za-z0-9]+)?/;

		my ($tmajor, $tminor, $talpha, $tfork) = ($1, $2, $3, $4);

		$rfork ||= '';
		$tfork ||= '';

		# 2.0 is better than 1.0.
		# 1.2 is better than 1.1.
		# 1.2a is better than 1.2.
		# If we require 3.4n-foo then we require something
		# >= 3.4n, with the `foo' fork identifier.
		if ($rmajor > $tmajor
		    || ($rmajor == $tmajor && $rminor > $tminor)
		    || ($rminor == $tminor && $rminor == $tminor
			&& $ralpha gt $talpha)
		    || ($rfork ne '' && $rfork ne $tfork))
		  {
		    &am_line_error ('AUTOMAKE_OPTIONS',
				    "require version $_, but have $VERSION");
		    return 1;
		  }
	    }
	    else
	    {
		&am_line_error ('AUTOMAKE_OPTIONS',
				"option `" . $_ . "\' not recognized");
	    }
	}
    }

    if ($strictness == $GNITS)
    {
	$options{'readme-alpha'} = 1;
	$options{'check-news'} = 1;
    }

    return 0;
}


# get_object_extension ($OUT)
# ---------------------------
# Return object extension.  Just once, put some code into the output.
# OUT is the name of the output file
sub get_object_extension
{
    my ($out) = @_;

    # Maybe require libtool library object files.
    my $extension = '.$(OBJEXT)';
    $extension = '.lo' if ($out =~ /\.la$/);

    # Check for automatic de-ANSI-fication.
    $extension = '$U' . $extension
      if defined $options{'ansi2knr'};

    $get_object_extension_was_run = 1;

    return $extension;
}


# Call finish function for each language that was used.
sub handle_languages
{
    if ($use_dependencies)
    {
	# Include auto-dep code.  Don't include it if DEP_FILES would
	# be empty.
	if (&saw_sources_p (0) && keys %dep_files)
	{
	    my $config_aux_dir_specified = ($config_aux_dir ne '.'
					    && $config_aux_dir ne '');

	    # Set $require_file_found{'depcomp'} if the depcomp file exists,
	    # before calling require_config_file on `depcomp'.  This makes
	    # require_file_internal skip its buggy existence test that would
	    # make automake fail (with `required file `lib/depcomp' not found')
	    # when AC_CONFIG_AUX_DIR is not set.  See tests/subdir4.test.
	    my $depcomp_dir = ($config_aux_dir_specified ? $config_aux_dir
			       : '.');
	    $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";

	    # Set location of depcomp.
	    my $prefix = ($config_aux_dir_specified ? $config_aux_dir
			  : '$(top_srcdir)');

	    &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");

	    &require_config_file ($FOREIGN, 'depcomp');

	    my @deplist = sort keys %dep_files;

	    # We define this as a conditional variable because BSD
	    # make can't handle backslashes for continuing comments on
	    # the following line.
	    &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);

	    # Generate each `include' individually.  Irix 6 make will
	    # not properly include several files resulting from a
	    # variable expansion; generating many separate includes
	    # seems safest.
	    $output_rules .= "\n";
	    foreach my $iter (@deplist)
 	    {
		# The strange concatentation is used to avoid
		# substitutions from our own configure.
		$output_rules .= ('@AMDEP' . '_TRUE@@_am_include@ @_am_quote@'
				  . $iter . '@_am_quote@' . "\n");
	    }

	    $output_rules .= &file_contents ('depend');
	}
    }
    else
    {
	&define_variable ('depcomp', '');
    }

    my ($ltcompile, $ltlink) = &libtool_compiler;
    my %done;

    # Is the c linker needed?
    my $needs_c = 0;
    foreach my $ext (sort keys %extension_seen)
      {
	my $lang = $languages{$extension_map{$ext}};

	# Get information on $LANG.
	my $pfx = $lang->autodep;
	my $fpfx = ($pfx eq '') ? 'CC' : $pfx;

	my $AMDEP = (($use_dependencies && $lang->autodep ne 'no')
		     ? 'AMDEP' : 'FALSE');

	my %transform = ('EXT'     => $ext,
			 'PFX'     => $pfx,
			 'FPFX'    => $fpfx,
			 'LIBTOOL' => $seen_libtool,
			 'AMDEP'   => $AMDEP,
			 '-c'      => $lang->compile_flag || '');

	# Generate the appropriate rules for this extension.
	if ($use_dependencies && $lang->autodep ne 'no'
	    || defined $lang->compile)
	  {
	    # Some C compilers don't support -c -o.  Use it only if really
	    # needed.
	    my $output_flag = $lang->output_flag || '';
	    $output_flag = '-o'
	      if (! $output_flag
		  && $lang->flags eq 'CFLAGS'
		  && defined $options{'subdir-objects'});

	    $output_rules .=
	      file_contents ('depend2',
			     %transform,
			     'GENERIC'   => 1,

			     'BASE'      => '$*',
			     'SOURCE'    => '$<',
			     'OBJ'       => '$@',
			     'OBJOBJ'    => '$@',
			     'LTOBJ'     => '$@',

			     'COMPILE'   => '$(' . $lang->compiler . ')',
			     'LTCOMPILE' => '$(LT' . $lang->compiler . ')',
			     '-o'        => $output_flag);
	  }

	# Now include code for each specially handled object with this
	# language.
	my %seen_files = ();
	foreach my $file (@{$lang_specific_files{$lang->name}})
	  {
	    my ($derived, $source, $obj) = split (' ', $file);

	    # We might see a given object twice, for instance if it is
	    # used under different conditions.
	    next if defined $seen_files{$obj};
	    $seen_files{$obj} = 1;

	    my $flags = $lang->flags || '';
	    my $val = "${derived}_${flags}";

	    (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
	    my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;

	    # We _need_ `-o' for per object rules.
	    my $output_flag = $lang->output_flag || '-o';

	    # Generate a transform which will turn suffix targets in
	    # depend2.am into real targets for the particular objects we
	    # are building.
	    $output_rules .=
	      file_contents ('depend2',
			     (%transform,
			      'GENERIC'   => 0,

			      'BASE'      => $obj,
			      'SOURCE'    => $source,
			      'OBJ'       => "$obj.o",
			      'OBJOBJ'    => "$obj.obj",
			      'LTOBJ'     => "$obj.lo",

			      'COMPILE'   => $obj_compile,
			      'LTCOMPILE' => $obj_ltcompile,
			      '-o'        => $output_flag));
	    }

	# The rest of the loop is done once per language.
	next if defined $done{$lang};
	$done{$lang} = 1;


	# If the source to a program consists entirely of code from a
	# `pure' language, for instance C++ for Fortran 77, then we
	# don't need the C compiler code.  However if we run into
	# something unusual then we do generate the C code.  There are
	# probably corner cases here that do not work properly.
	# People linking Java code to Fortran code deserve pain.
	$needs_c ||= ! $lang->pure;

	if ($lang->compile)
	  {
	    &define_compiler_variable ($lang->compiler,
				       $ltcompile, $lang->compile);
	  }

	# The compiler's flag must be a configure variable.
	if (defined $lang->flags)
	  {
	    &define_configure_variable ($lang->flags);
	  }

	# Call the finisher.
	$lang->finish;
      }

    # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
    # suffix rule was learned), don't bother with the C stuff.  But if
    # anything else creeps in, then use it.
    $needs_c = 1
      if $need_link || scalar keys %suffix_rules > 1;

    if ($needs_c)
      {
	if (! defined $done{$languages{'c'}})
	  {
	    &define_configure_variable ($languages{'c'}->flags);
	    &define_compiler_variable ($languages{'c'}->compiler,
				       $ltcompile,
				       $languages{'c'}->compile);
	  }
	&define_variable ('CCLD', '$(CC)');
	&define_variable ('LINK',
			  $ltlink . '$(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');
      }
}

# Output a rule to build from a YACC source.  The output from YACC is
# compiled with C or C++, depending on the extension of the YACC file.
sub output_yacc_build_rule
{
    my ($yacc_suffix, $use_ylwrap) = @_;

    (my $c_suffix = $yacc_suffix) =~ tr/y/c/;

    # Generate rule for c/c++.
    $output_rules .= &file_contents ('yacc',
				     ('YLWRAP'      => $use_ylwrap,
				      'YACC_SUFFIX' => $yacc_suffix,
				      'C_SUFFIX'    => $c_suffix));
}

sub output_lex_build_rule
{
    my ($lex_suffix, $use_ylwrap) = @_;

    (my $c_suffix = $lex_suffix) =~ tr/l/c/;

    $output_rules .= &file_contents ('lex',
				     ('YLWRAP'     => $use_ylwrap,
				      'LEX_SUFFIX' => $lex_suffix,
				      'C_SUFFIX'   => $c_suffix));
}

    if ($use_dependencies)
    {
	# Include auto-dep code.  Don't include it if DEP_FILES would
	# be empty.
	if (&saw_sources_p (0) && keys %dep_files)
	{
	    my $config_aux_dir_specified = ($config_aux_dir ne '.'
					    && $config_aux_dir ne '');

	    # Set $require_file_found{'depcomp'} if the depcomp file exists,
	    # before calling require_config_file on `depcomp'.  This makes
	    # require_file_internal skip its buggy existence test that would
	    # make automake fail (with `required file `lib/depcomp' not found')
	    # when AC_CONFIG_AUX_DIR is not set.  See tests/subdir4.test.
	    my $depcomp_dir = ($config_aux_dir_specified ? $config_aux_dir
			       : '.');
	    $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";

	    # Set location of depcomp.
	    my $prefix = ($config_aux_dir_specified ? $config_aux_dir
			  : '$(top_srcdir)');

	    &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");

	    &require_config_file ($FOREIGN, 'depcomp');

	    my @deplist = sort keys %dep_files;

	    # We define this as a conditional variable because BSD
	    # make can't handle backslashes for continuing comments on
	    # the following line.
	    &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);

	    # Generate each `include' individually.  Irix 6 make will
	    # not properly include several files resulting from a
	    # variable expansion; generating many separate includes
	    # seems safest.
	    $output_rules .= "\n";
	    foreach my $iter (@deplist)
 	    {
		# The strange concatentation is used to avoid
		# substitutions from our own configure.
		$output_rules .= ('@AMDEP' . '_TRUE@@_am_include@ '
				  . $iter . "\n");
	    }

	    $output_rules .= &file_contents ('depend');
	}
    }
    else
    {
	&define_variable ('depcomp', '');
    }

# Check to make sure a source defined in LIBOBJS is not explicitly
# mentioned.  This is a separate function (as opposed to being inlined
# in handle_source_transform) because it isn't always appropriate to
# do this check.
sub check_libobjs_sources
{
    my ($one_file, $unxformed) = @_;

    foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
			'dist_EXTRA_', 'nodist_EXTRA_')
    {
        my @files;
	if (&variable_defined ($prefix . $one_file . '_SOURCES'))
	{
	    @files = &variable_value_as_list (($prefix
					       . $one_file . '_SOURCES'),
					      'all');
	}
	elsif ($prefix eq '')
	{
	    @files = ($unxformed . '.c');
	}
	else
	{
	    next;
	}

	foreach my $file (@files)
	{
	    if (defined $libsources{$file})
	    {
		&am_line_error ($prefix . $one_file . '_SOURCES',
				"automatically discovered file `$file' should not be explicitly mentioned");
	    }
	}
    }
}

    if ($use_dependencies)
    {
	# Include auto-dep code.  Don't include it if DEP_FILES would
	# be empty.
	if (&saw_sources_p (0) && keys %dep_files)
	{
	    my $config_aux_dir_specified = ($config_aux_dir ne '.'
					    && $config_aux_dir ne '');

	    # Set $require_file_found{'depcomp'} if the depcomp file exists,
	    # before calling require_config_file on `depcomp'.  This makes
	    # require_file_internal skip its buggy existence test that would
	    # make automake fail (with `required file `lib/depcomp' not found')
	    # when AC_CONFIG_AUX_DIR is not set.  See tests/subdir4.test.
	    my $depcomp_dir = ($config_aux_dir_specified ? $config_aux_dir
			       : '.');
	    $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";

	    # Set location of depcomp.
	    my $prefix = ($config_aux_dir_specified ? $config_aux_dir
			  : '$(top_srcdir)');

	    &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");

	    &require_config_file ($FOREIGN, 'depcomp');

	    my @deplist = sort keys %dep_files;

	    # We define this as a conditional variable because BSD
	    # make can't handle backslashes for continuing comments on
	    # the following line.
	    &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);

	    # Generate each `include' individually.  Irix 6 make will
	    # not properly include several files resulting from a
	    # variable expansion; generating many separate includes
	    # seems safest.
	    $output_rules .= "\n";
	    foreach my $iter (@deplist)
 	    {
		$output_rules .= '@AMDEP_TRUE@@_am_include@ ' . $iter . "\n";
	    }

	    $output_rules .= &file_contents ('depend');
	}
    }
    else
    {
	&define_variable ('depcomp', '');
    }

# ($LINKER, @OBJECTS)
# handle_single_transform_list ($VAR, $DERIVED, $OBJ, @FILES)
# -----------------------------------------------------------
# Does much of the actual work for handle_source_transform.
# Arguments are:
#   $DERIVED is the name of resulting executable or library
#   $OBJ is the object extension (e.g., `$U.lo')
#   @FILES is the list of source files to transform
# Result is a list
#   $LINKER is name of linker to use (empty string for default linker)
#   @OBJECTS are names of objects
sub handle_single_transform_list ($$$@)
{
    my ($var, $derived, $obj, @files) = @_;
    my @result = ();
    my $nonansi_obj = $obj;
    $nonansi_obj =~ s/\$U//g;
    my %linkers_used = ();

    # Turn sources into objects.
    foreach (@files)
    {
        # Configure substitutions in _SOURCES variables are errors.
        if (/^\@.*\@$/)
        {
            &am_line_error ($var, "$var includes configure substitution `$_'");
            next;
        }

        # If the source file is in a subdirectory then the `.o' is
        # put into the current directory.

        # Split file name into base and extension.
        next if ! /^(?:(.*)\/)?([^\/]*)\.(.*)$/;
        my $full = $_;
        my $directory = $1 || '';
        my $base = $2;
        my $extension = $3;

        # We must generate a rule for the object if it requires its own flags.
        my $renamed = 0;
        my ($linker, $object);

        $extension = &derive_suffix ($extension);
        my $lang = $languages{$extension_map{$extension}};
        if ($lang)
        {
            &saw_extension ($extension);
            # Found the language, so see what it says.
            my $subr = 'lang_' . $lang->name . '_rewrite';
            # Note: computed subr call.
            my $r = & $subr ($directory, $base, $extension);
            # Skip this entry if we were asked not to process it.
            next if $r == $LANG_IGNORE;

            # Now extract linker and other info.
            $linker = $lang->linker;

            my $this_obj_ext;
            if ($lang->ansi)
            {
                $object = $base . $obj;
                $this_obj_ext = $obj;
            }
            else
            {
                $object = $base . $nonansi_obj;
                $this_obj_ext = $nonansi_obj;
            }

            if (defined $lang->flags
                && &variable_defined ($derived . '_' . $lang->flags))
            {
                # We have a per-executable flag in effect for this
                # object.  In this case we rewrite the object's
                # name to ensure it is unique.  We also require
                # the `compile' program to deal with compilers
                # where `-c -o' does not work.

                # We choose the name `DERIVED_OBJECT' to ensure
                # (1) uniqueness, and (2) continuity between
                # invocations.  However, this will result in a
                # name that is too long for losing systems, in
                # some situations.  So we provide _SHORTNAME to
                # override.

                my $dname = $derived;
                if (&variable_defined ($derived . '_SHORTNAME'))
                {
                    # FIXME: should use the same conditional as
                    # the _SOURCES variable.  But this is really
                    # silly overkill -- nobody should have
                    # conditional shortnames.
                    $dname = &variable_value ($derived . '_SHORTNAME');
                }
                $object = $dname . '-' . $object;

                &require_file ($FOREIGN, 'compile')
                    if $lang->name eq 'c';

                &prog_error ("$lang->name flags defined without compiler")
  		    if ! defined $lang->compile;

                $renamed = 1;
            }

            # If rewrite said it was ok, put the object into a
            # subdir.
            if ($r == $LANG_SUBDIR && $directory ne '')
            {
                $object = $directory . '/' . $object;
            }

            # If doing dependency tracking, then we can't print
            # the rule.  If we have a subdir object, we need to
            # generate an explicit rule.  Actually, in any case
            # where the object is not in `.' we need a special
            # rule.  The per-object rules in this case are
            # generated later, by handle_languages.
            if ($renamed || $directory ne '')
            {
                my $obj_sans_ext = substr ($object, 0,
					   - length ($this_obj_ext));
                push (@{$lang_specific_files{$lang->name}},
		      "$derived $full $obj_sans_ext");
            }
        }
        elsif ($extension eq 'o')
        {
            # This is probably the result of a direct suffix rule.
            # In this case we just accept the rewrite.  FIXME:
            # this fails if we want libtool objects.
            $object = $base . '.' . $extension;
            $linker = '';
        }
        else
        {
            # No error message here.  Used to have one, but it was
            # very unpopular.
            next;
        }

        $linkers_used{$linker} = 1;

        push (@result, $object);

        if (defined $object_map{$object})
        {
            if ($object_map{$object} ne $full)
            {
                &am_error ("object `$object' created by `$full' and `$object_map{$object}'");
            }
        }
        else
        {
            my @dep_list = ();
            $object_map{$object} = $full;

            # If file is in subdirectory, we need explicit
            # dependency.
            if ($directory ne '' || $renamed)
            {
                push (@dep_list, $full);
            }

            # If resulting object is in subdir, we need to make
            # sure the subdir exists at build time.
            if ($object =~ /\//)
            {
                # FIXME: check that $DIRECTORY is somewhere in the
                # project

                # We don't allow `..' in object file names for
                # *any* source, not just Java.  For Java it just
                # doesn't make sense, but in general it is
                # a problem because we can't pick a good name for
                # the .deps entry.
                if ($object =~ /(\/|^)\.\.\//)
                {
                    &am_error ("`$full' contains `..' component but should not");
                }

                push (@dep_list, $directory . '/.dirstamp');

                # If we're generating dependencies, we also want
                # to make sure that the appropriate subdir of the
                # .deps directory is created.
                if ($use_dependencies)
                {
                    push (@dep_list, '.deps/' . $directory . '/.dirstamp');
                }

                if (! defined $directory_map{$directory})
                {
                    $directory_map{$directory} = 1;
                    $output_rules .= ($directory . "/.dirstamp:\n"
                                      . "\t\@\$(mkinstalldirs) $directory\n"
                                      . "\t\@: > $directory/.dirstamp\n");
                    if ($use_dependencies)
                    {
                        $output_rules .= ('.deps/' . $directory
                                          . "/.dirstamp:\n"
                                          . "\t\@\$(mkinstalldirs) .deps/$directory\n"
                                          . "\t\@: > .deps/$directory/.dirstamp\n");
                    }
                }
            }

            &pretty_print_rule ($object . ':', "\t", @dep_list)
                if scalar @dep_list > 0;
        }

        # Transform .o or $o file into .P file (for automatic
        # dependency code).
        if ($lang
            && ($lang->autodep ne 'no'
                || $lang->derived_autodep eq 'yes'))
        {
            my $depfile = $object;
            $depfile =~ s/\.([^.]*)$/.P$1/;
            $depfile =~ s/\$\(OBJEXT\)$/o/;
            $dep_files{'$(DEPDIR)/' . $depfile} = 1;
        }
    }

    return (&resolve_linker (%linkers_used), @result);
}



# Handle SOURCE->OBJECT transform for one program or library.
# Arguments are:
#   canonical (transformed) name of object to build
#   actual name of object to build
#   object extension (ie either `.o' or `$o'.
# Return result is name of linker variable that must be used.
# Empty return means just use `LINK'.
sub handle_source_transform
{
    # one_file is canonical name.  unxformed is given name.  obj is
    # object extension.
    my ($one_file, $unxformed, $obj) = @_;

    my ($linker) = '';

    if (&variable_defined ($one_file . "_OBJECTS"))
    {
	&am_line_error ($one_file . '_OBJECTS',
			$one_file . '_OBJECTS', 'should not be defined');
	# No point in continuing.
	return;
    }

    my %used_pfx = ();
    foreach my $prefix ('', 'EXTRA_', 'dist_', 'nodist_',
			'dist_EXTRA_', 'nodist_EXTRA_')
    {
	my $var = $prefix . $one_file . "_SOURCES";
	next
	  if !variable_defined ($var);

	# We are going to define _OBJECTS variables using the prefix.
	# Then we glom them all together.  So we can't use the null
	# prefix here as we need it later.
	my $xpfx = ($prefix eq '') ? 'am_' : $prefix;

	# Keep track of which prefixes we saw.
	$used_pfx{$xpfx} = 1
	  unless $prefix =~ /EXTRA_/;

	push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
	push (@objects, '$(' . $xpfx . $one_file . "_OBJECTS)")
	  unless $prefix =~ /EXTRA_/;
	push (@dist_sources, '$(' . $prefix . $one_file . "_SOURCES)")
	  unless $prefix =~ /^nodist_/;
	foreach my $cond (variable_conditions ($var))
	  {
	    my @files = &variable_value_as_list ($var, $cond);
	    my ($temp, @result) =
	      &handle_single_transform_list ($var, $one_file, $obj,
					     @files);
	    # If there are no files to compile, don't require a linker (yet).
	    $linker ||= $temp
	      if @files;

	    # Define _OBJECTS conditionally.
	    &define_pretty_variable ($xpfx . $one_file . '_OBJECTS',
				     $cond, @result)
	      unless $prefix =~ /EXTRA_/;
	  }
    }

    my @keys = sort keys %used_pfx;
    if (scalar @keys == 0)
    {
	&define_variable ($one_file . "_SOURCES", $unxformed . ".c");
	push (@sources, $unxformed . '.c');
	push (@dist_sources, $unxformed . '.c');
	push (@objects, $unxformed . $obj);

	my ($temp, @result) =
	  &handle_single_transform_list ($one_file . '_SOURCES',
					 $one_file, $obj,
					 "$unxformed.c");
	$linker = $temp if $linker eq '';
	&define_pretty_variable ($one_file . "_OBJECTS", '', @result)
    }
    else
    {
	grep ($_ = '$(' . $_ . $one_file . '_OBJECTS)', @keys);
	&define_pretty_variable ($one_file . '_OBJECTS', '', @keys);
    }

    # If we want to use `LINK' we must make sure it is defined.
    if ($linker eq '')
    {
	$need_link = 1;
    }

    return $linker;
}


# handle_lib_objects ()
# ---------------------
# Special-case @ALLOCA@ and @LIBOBJS@ in _LDADD or _LIBADD variables.
# Also, generate _DEPENDENCIES variable if appropriate.
# Arguments are:
#   transformed name of object being built, or empty string if no object
#   name of _LDADD/_LIBADD-type variable to examine
#   boolean (lex_seen) which is true if a lex source file was seen in this
#     object.  valid only for LDADDs, not LIBADDs.
# Returns 1 if LIBOBJS seen, 0 otherwise.
sub handle_lib_objects
{
    my ($xname, $var, $lex_seen) = @_;

    &prog_error ("handle_lib_objects: $var undefined")
	if ! &variable_defined ($var);

    &prog_error ("handle_lib_objects: lex_seen and $var =~ /LIBADD/")
	if $lex_seen && $var =~ /LIBADD/;

    my $ret = 0;
    foreach my $cond (&variable_conditions ($var))
      {
	if (&handle_lib_objects_cond ($xname, $var, $lex_seen, $cond))
	  {
	    $ret = 1;
	  }
      }
    return $ret;
}

# Subroutine of handle_lib_objects: handle a particular condition.
sub handle_lib_objects_cond
{
    my ($xname, $var, $lex_seen, $cond) = @_;

    # We recognize certain things that are commonly put in LIBADD or
    # LDADD.
    my @dep_list = ();

    my $seen_libobjs = 0;
    my $flagvar = 0;

    foreach my $lsearch (&variable_value_as_list ($var, $cond))
    {
	# Skip -lfoo and -Ldir; these are explicitly allowed.
	next if $lsearch =~ /^-[lL]/;
	if (! $flagvar && $lsearch =~ /^-/)
	{
	    if ($var =~ /^(.*)LDADD$/)
	    {
		# Skip -dlopen and -dlpreopen; these are explicitly allowed.
		next if $lsearch =~ /^-dl(pre)?open$/;
		&am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
	    }
	    else
	    {
		# Only get this error once.
		$flagvar = 1;
		&am_line_error ($var, "linker flags such as `$lsearch' belong in `${1}LDFLAGS");
	    }
	}

	# Assume we have a file of some sort, and push it onto the
	# dependency list.  Autoconf substitutions are not pushed;
	# rarely is a new dependency substituted into (eg) foo_LDADD
	# -- but "bad things (eg -lX11) are routinely substituted.
	# Note that LIBOBJS and ALLOCA are exceptions to this rule,
	# and handled specially below.
	push (@dep_list, $lsearch)
	    unless $lsearch =~ /^\@.*\@$/;

	# Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
	# means adding entries to dep_files.
	if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
	{
	    my $myobjext = ($1 ? 'l' : '') . 'o';

	    push (@dep_list, $lsearch);
	    $seen_libobjs = 1;
	    if (! keys %libsources
		&& ! &variable_defined ($1 . 'LIBOBJS'))
	    {
		&am_line_error ($var, "\@$1" . "LIBOBJS\@ seen but never set in `$configure_ac'");
	    }

	    foreach my $iter (keys %libsources)
	    {
		if ($iter =~ /\.([cly])$/)
		{
		    &saw_extension ($1);
		    &saw_extension ('c');
		}

		if ($iter =~ /\.h$/)
		{
		    &require_file_with_line ($var, $FOREIGN, $iter);
		}
		elsif ($iter ne 'alloca.c')
		{
		    my $rewrite = $iter;
		    $rewrite =~ s/\.c$/.P$myobjext/;
		    $dep_files{'$(DEPDIR)/' . $rewrite} = 1;
		    ($rewrite = $iter) =~ s/(\W)/\\$1/g;
		    $rewrite = "^" . $rewrite . "\$";
		    # Only require the file if it is not a built source.
		    if (! &variable_defined ('BUILT_SOURCES')
			|| ! grep (/$rewrite/,
				   &variable_value_as_list ('BUILT_SOURCES',
							    'all')))
		    {
			&require_file_with_line ($var, $FOREIGN, $iter);
		    }
		}
	    }
	}
	elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
	{
	    my $myobjext = ($1 ? 'l' : '') . 'o';

	    push (@dep_list, $lsearch);
	    &am_line_error ($var,
			    "\@$1" . "ALLOCA\@ seen but `AC_FUNC_ALLOCA' not in `$configure_ac'")
		if ! defined $libsources{'alloca.c'};
	    $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1;
	    &require_file_with_line ($var, $FOREIGN, 'alloca.c');
	    &saw_extension ('c');
	}
    }

    if ($xname ne '' && ! &variable_defined ($xname . '_DEPENDENCIES', $cond))
    {
	&define_pretty_variable ($xname . '_DEPENDENCIES', $cond, @dep_list);
    }

    return $seen_libobjs;
}

# Canonicalize the input parameter
sub canonicalize
{
    my ($string) = @_;
    $string =~ tr/A-Za-z0-9_\@/_/c;
    return $string;
}

# Canonicalize a name, and check to make sure the non-canonical name
# is never used.  Returns canonical name.  Arguments are name and a
# list of suffixes to check for.
sub check_canonical_spelling
{
    my ($name, @suffixes) = @_;

    my $xname = &canonicalize ($name);
    if ($xname ne $name)
    {
	foreach my $xt (@suffixes)
	{
	    &am_line_error ($name . $xt,
			    "invalid variable `" . $name . $xt
			    . "'; should be `" . $xname . $xt . "'")
		if &variable_defined ($name . $xt);
	}
    }

    return $xname;
}


# handle_compile ()
# -----------------
# Set up the compile suite.
sub handle_compile ()
{
    return
      unless $get_object_extension_was_run;

    # Boilerplate.
    my $default_includes = '';
    if (! defined $options{'nostdinc'})
      {
	$default_includes = ' -I. -I$(srcdir)';

	if (&variable_defined ('CONFIG_HEADER'))
	  {
	    foreach my $hdr (split (' ', &variable_value ('CONFIG_HEADER')))
	      {
		$default_includes .= ' -I' . dirname ($hdr);
	      }
	  }
      }

    my ($coms, $vars, $rules) =
      &file_contents_internal ('compile',
			       ('DEFAULT_INCLUDES' => $default_includes));
    $output_vars .= $vars;
    $output_rules .= "$coms$rules";

    if ($seen_libtool)
      {
	# Output the libtool compilation rules.
	$output_rules .= &file_contents ('libtool');
      }

    # Check for automatic de-ANSI-fication.
    if (defined $options{'ansi2knr'})
      {
	if (! $am_c_prototypes)
	  {
	    &am_line_error ('AUTOMAKE_OPTIONS',
			    "option `ansi2knr' in use but `AM_C_PROTOTYPES' not in `$configure_ac'");
	    &keyed_aclocal_warning ('AM_C_PROTOTYPES');
	    # Only give this error once.
	    $am_c_prototypes = 1;
	  }

	# topdir is where ansi2knr should be.
	if ($options{'ansi2knr'} eq 'ansi2knr')
	  {
	    # Only require ansi2knr files if they should appear in
	    # this directory.
	    &require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
				     'ansi2knr.c', 'ansi2knr.1');

	    # ansi2knr needs to be built before subdirs, so unshift it.
	    unshift (@all, '$(ANSI2KNR)');
	  }

	my $ansi2knr_dir = '';
	$ansi2knr_dir = dirname ($options{'ansi2knr'})
	  if $options{'ansi2knr'} ne 'ansi2knr';

	$output_rules .= &file_contents ('ansi2knr',
					 ('ANSI2KNR-DIR' => $ansi2knr_dir));

    }
}



# handle_programs ()
# ------------------
# Handle C programs.
sub handle_programs
{
    my @proglist = &am_install_var ('progs', 'PROGRAMS',
				    'bin', 'sbin', 'libexec', 'pkglib',
				    'noinst', 'check');
    return if ! @proglist;

    my $seen_libobjs = 0;
    foreach my $one_file (@proglist)
    {
	my $obj = &get_object_extension ($one_file);

	# Canonicalize names and check for misspellings.
	my $xname = &check_canonical_spelling ($one_file, '_LDADD', '_LDFLAGS',
					       '_SOURCES', '_OBJECTS',
					       '_DEPENDENCIES');

	# FIXME: Using a trick to figure out if any lex sources appear
	# in our program; should use some cleaner method.
	my $lex_num = scalar (keys %lex_sources);
	my $linker = &handle_source_transform ($xname, $one_file, $obj);
	my $lex_file_seen = (scalar (keys %lex_sources) > $lex_num);

	my $xt = '';
	if (&variable_defined ($xname . "_LDADD"))
	{
	    if (&handle_lib_objects ($xname, $xname . '_LDADD',
				     $lex_file_seen))
	    {
		$seen_libobjs = 1;
	    }
	    $lex_file_seen = 0;
	    $xt = '_LDADD';
	}
	else
	{
	    # User didn't define prog_LDADD override.  So do it.
	    &define_variable ($xname . '_LDADD', '$(LDADD)');

	    # This does a bit too much work.  But we need it to
	    # generate _DEPENDENCIES when appropriate.
	    if (&variable_defined ('LDADD'))
	    {
		if (&handle_lib_objects ($xname, 'LDADD', $lex_file_seen))
		{
		    $seen_libobjs = 1;
		}
		$lex_file_seen = 0;
	    }
	    elsif (! &variable_defined ($xname . '_DEPENDENCIES'))
	    {
		&define_variable ($xname . '_DEPENDENCIES', '');
	    }
	    $xt = '_SOURCES'
	}

	if (&variable_defined ($xname . '_LIBADD'))
	{
	    &am_line_error ($xname . '_LIBADD',
			    "use `" . $xname . "_LDADD', not `"
			    . $xname . "_LIBADD'");
	}

	if (! &variable_defined ($xname . '_LDFLAGS'))
	{
	    # Define the prog_LDFLAGS variable.
	    &define_variable ($xname . '_LDFLAGS', '');
	}

	# Determine program to use for link.
	my $xlink;
	if (&variable_defined ($xname . '_LINK'))
	{
	    $xlink = $xname . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	$output_rules .= &file_contents ('program',
					 ('PROGRAM'  => $one_file,
					  'XPROGRAM' => $xname,
					  'XLINK'    => $xlink));
    }

    if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
    {
	$seen_libobjs = 1;
    }

    if ($seen_libobjs)
    {
	foreach my $one_file (@proglist)
	{
	    my $xname = &canonicalize ($one_file);

	    if (&variable_defined ($xname . '_LDADD'))
	    {
		&check_libobjs_sources ($xname, $xname . '_LDADD');
	    }
	    elsif (&variable_defined ('LDADD'))
	    {
		&check_libobjs_sources ($xname, 'LDADD');
	    }
	}
    }
}


# handle_libraries ()
# -------------------
# Handle libraries.
sub handle_libraries
{
    my @liblist = &am_install_var ('libs', 'LIBRARIES',
				   'lib', 'pkglib', 'noinst', 'check');
    return if ! @liblist;

    my %valid = &am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib',
				      'noinst', 'check');
    if (! defined $configure_vars{'RANLIB'})
    {
	foreach my $key (keys %valid)
	{
	    if (&variable_defined ($key . '_LIBRARIES'))
	    {
		&am_line_error ($key . '_LIBRARIES', "library used but `RANLIB' not defined in `$configure_ac'");
		# Only get this error once.  If this is ever printed,
		# we have a bug.
		$configure_vars{'RANLIB'} = 'BUG';
		last;
	    }
	}
    }

    my $seen_libobjs = 0;
    foreach my $onelib (@liblist)
    {
	# Check that the library fits the standard naming convention.
	if ($onelib !~ /^lib.*\.a$/)
	{
	    # FIXME should put line number here.  That means mapping
	    # from library name back to variable name.
	    &am_error ("`$onelib' is not a standard library name");
	}

	my $obj = &get_object_extension ($onelib);

	# Canonicalize names and check for misspellings.
	my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
					      '_OBJECTS', '_DEPENDENCIES',
					      '_AR');

	if (! &variable_defined ($xlib . '_AR'))
	{
	    &define_variable ($xlib . '_AR', '$(AR) cru');
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use `" . $xlib . "_LIBADD', not `"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	&handle_source_transform ($xlib, $onelib, $obj);

	$output_rules .= &file_contents ('library',
					 ('LIBRARY'  => $onelib,
					  'XLIBRARY' => $xlib));
    }

    if ($seen_libobjs)
    {
	foreach my $onelib (@liblist)
	{
	    my $xlib = &canonicalize ($onelib);
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}


# handle_ltlibraries ()
# ---------------------
# Handle shared libraries.
sub handle_ltlibraries
{
    my @liblist = &am_install_var ('ltlib', 'LTLIBRARIES',
				   'noinst', 'lib', 'pkglib', 'check');
    return if ! @liblist;

    my %instdirs;
    my %valid = &am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib',
				      'noinst', 'check');

    foreach my $key (keys %valid)
    {
	if (&variable_defined ($key . '_LTLIBRARIES'))
	{
	    if (!$seen_libtool)
	    {
		&am_line_error ($key . '_LTLIBRARIES', "library used but `LIBTOOL' not defined in `$configure_ac'");
		# Only get this error once.  If this is ever printed,
		# we have a bug.
		$configure_vars{'LIBTOOL'} = 'BUG';
		$seen_libtool = 1;
	    }

	    # Get the installation directory of each library.
	    for (&variable_value_as_list ($key . '_LTLIBRARIES', 'all'))
	    {
		if ($instdirs{$_})
		{
		    &am_error ("`$_' is already going to be installed in `$instdirs{$_}'");
		}
		else
		{
		    $instdirs{$_} = $key;
		}
	    }
	}
    }

    my $seen_libobjs = 0;
    foreach my $onelib (@liblist)
    {
	my $obj = &get_object_extension ($onelib);

	# Canonicalize names and check for misspellings.
	my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_LDFLAGS',
					      '_SOURCES', '_OBJECTS',
					      '_DEPENDENCIES');

	if (! &variable_defined ($xlib . '_LDFLAGS'))
	{
	    # Define the lib_LDFLAGS variable.
	    &define_variable ($xlib . '_LDFLAGS', '');
	}

	# Check that the library fits the standard naming convention.
    	my $libname_rx = "^lib.*\.la";
	if ((&variable_defined ($xlib . '_LDFLAGS')
	     && grep (/-module/, &variable_value_as_list ($xlib . '_LDFLAGS',
							  'all')))
	    || (&variable_defined ('LDFLAGS')
		&& grep (/-module/, &variable_value_as_list ('LDFLAGS',
							     'all'))))
	{
		# Relax name checking for libtool modules.
	    	$libname_rx = "\.la";
	}
	if ($onelib !~ /$libname_rx$/)
	{
	    # FIXME this should only be a warning for foreign packages
	    # FIXME should put line number here.  That means mapping
	    # from library name back to variable name.
	    &am_error ("`$onelib' is not a standard libtool library name");
	}

	if (&variable_defined ($xlib . '_LIBADD'))
	{
	    if (&handle_lib_objects ($xlib, $xlib . '_LIBADD', 0))
	    {
		$seen_libobjs = 1;
	    }
	}
	else
	{
	    # Generate support for conditional object inclusion in
	    # libraries.
	    &define_variable ($xlib . "_LIBADD", '');
	}

	if (&variable_defined ($xlib . '_LDADD'))
	{
	    &am_line_error ($xlib . '_LDADD',
			    "use `" . $xlib . "_LIBADD', not `"
			    . $xlib . "_LDADD'");
	}

	# Make sure we at look at this.
	&examine_variable ($xlib . '_DEPENDENCIES');

	my $linker = &handle_source_transform ($xlib, $onelib, $obj);

	# Determine program to use for link.
	my $xlink;
	if (&variable_defined ($xlib . '_LINK'))
	{
	    $xlink = $xlib . '_LINK';
	}
	else
	{
	    $xlink = $linker ? $linker : 'LINK';
	}

	my $rpath;
	if ($instdirs{$onelib} eq 'EXTRA'
	    || $instdirs{$onelib} eq 'noinst'
	    || $instdirs{$onelib} eq 'check')
	{
	    # It's an EXTRA_ library, so we can't specify -rpath,
	    # because we don't know where the library will end up.
	    # The user probably knows, but generally speaking automake
	    # doesn't -- and in fact configure could decide
	    # dynamically between two different locations.
	    $rpath = '';
	}
	else
	{
	    $rpath = ('-rpath $(' . $instdirs{$onelib} . 'dir)');
	}

	$output_rules .= &file_contents ('ltlibrary',
					 ('LTLIBRARY'  => $onelib,
					  'XLTLIBRARY' => $xlib,
					  'RPATH'      => $rpath,
					  'XLINK'      => $xlink));
    }

    if ($seen_libobjs)
    {
	foreach my $onelib (@liblist)
	{
	    my $xlib = &canonicalize ($onelib);
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }
}

# See if any _SOURCES variable were misspelled.  Also, make sure that
# EXTRA_ variables don't contain configure substitutions.
sub check_typos
{
    foreach my $varname (keys %var_value)
    {
	foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
			     '_DEPENDENCIES')
	{
	    if ($varname =~ /$primary$/ && ! $content_seen{$varname})
	    {
		&am_line_error ($varname,
				"invalid unused variable name: `$varname'");
	    }
	}
    }
}

# Handle scripts.
sub handle_scripts
{
    # NOTE we no longer automatically clean SCRIPTS, because it is
    # useful to sometimes distribute scripts verbatim.  This happens
    # eg in Automake itself.
    &am_install_var ('-candist', 'scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    my $scripts_installed = 0;
    # Set $scripts_installed if appropriate.  Make sure we only find
    # scripts which are actually installed -- this is why we can't
    # simply use the return value of am_install_var.
    my %valid = &am_primary_prefixes ('SCRIPTS', 1, 'bin', 'sbin',
				      'libexec', 'pkgdata',
				      'noinst', 'check');
    foreach my $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check_tests, 'check-' . $key . 'SCRIPTS');
	}
    }
}


# ($OUTFILE, $VFILE, @CLEAN_FILES)
# &scan_texinfo_file ($FILENAME)
# ------------------------------
# $OUTFILE is the name of the info file produced by $FILENAME.
# $VFILE is the name of the version.texi file used (empty if none).
# @CLEAN_FILES is the list of by products (indexes etc.)
sub scan_texinfo_file
{
    my ($filename) = @_;

    # These are always created, no matter whether indexes are used or not.
    my @clean_suffixes = ('aux', 'dvi', 'log', 'ps', 'toc',
			  # grep new.*index texinfo.tex
			  'cp', 'fn', 'ky', 'vr', 'tp', 'pg');

    # There are predefined indexes which don't follow the regular rules.
    my %predefined_index =
      (
       # cindex => *.cps
       'c' => 'cps', 'f' => 'fns', 'k' => 'kys',
       'v' => 'vrs', 't' => 'tps', 'p' => 'pgs'
      );

    # There are commands which include a hidden index command.
    my %hidden_index =
      (
       # deffn => *.fns.
       'fn' => 'fns',     'un' => 'fns',
       'typefn' => 'fns', 'typefun' => 'fns',
       'mac' => 'fns', 'spec' => 'fns',
       'op' => 'fns',  'typeop' => 'fns',
       'method' => 'fns', 'typemethod' => 'fns',

       'vr' => 'vrs', 'var' => 'vrs',
       'typevr' => 'vrs', 'typevar' => 'vrs',
       'opt' => 'vrs',
       'cv' => 'vrs',
       'ivar' => 'vrs', 'typeivar' => 'vrs',

       'tp' => 'tps'
      );

    # Indexes stored into another one.  In this case, the *.??s file
    # is not created.
    my @syncodeindexes = ();

    my $texi = new IO::File ("< $filename");
    if (! $texi)
      {
	&am_error ("couldn't open `$filename': $!");
	return '';
    }
    print "$me: reading $filename\n" if $verbose;

    my ($outfile, $vfile);
    while ($_ = $texi->getline)
    {
      if (/^\@setfilename +(\S+)/)
      {
        $outfile = $1;
        if ($outfile =~ /\.(.+)$/ && $1 ne 'info')
          {
            &am_file_error ($filename, "$.: ",
                            "output `$outfile' has unrecognized extension");
            return;
          }
      }
      # A "version.texi" file is actually any file whose name
      # matches "vers*.texi".
      elsif (/^\@include\s+(vers[^.]*\.texi)\s*$/)
      {
        $vfile = $1;
      }

      # Try to find what are the indexes which are used.

      # Creating a new category of index.
      elsif (/^\@def(code)?index (\w+)/)
      {
        push @clean_suffixes, $2;
      }

      # Storing in a predefined index.
      elsif (/^\@([cfkvtp])index /)
      {
        push @clean_suffixes, $predefined_index{$1};
      }
      elsif (/^\@def(\w+) /)
      {
	push @clean_suffixes, $hidden_index{$1}
	  if defined $hidden_index{$1};
      }

      # Merging an index into an another.
      elsif (/^\@syn(code)?index (\w+) \w+/)
      {
	push @syncodeindexes, "$2s";
      }

    }
    $texi->close;

    if ($outfile eq '')
      {
	&am_error ("`$filename' missing \@setfilename");
	return;
      }

    my $infobase = basename ($filename);
    $infobase =~ s/\.te?xi(nfo)?$//;
    my %clean_files;
    grep { $clean_files{"$infobase.$_"} = 1    } @clean_suffixes;
    grep { delete $clean_files{"$infobase.$_"} } @syncodeindexes;
    return ($outfile, $vfile, (sort keys %clean_files));
}


# handle_texinfo ()
# -----------------
# Handle all Texinfo source.
sub handle_texinfo
{
    &am_line_error ('TEXINFOS',
		    "`TEXINFOS' is an anachronism; use `info_TEXINFOS'")
	if &variable_defined ('TEXINFOS');
    return if (! &variable_defined ('info_TEXINFOS')
	       && ! &variable_defined ('html_TEXINFOS'));

    if (&variable_defined ('html_TEXINFOS'))
    {
	&am_line_error ('html_TEXINFOS',
			"HTML generation not yet supported");
	return;
    }

    my @texis = &variable_value_as_list ('info_TEXINFOS', 'all');

    my (@info_deps_list, @dvis_list, @texi_deps);
    my %versions;
    my $done = 0;
    my @texi_cleans;
    my $canonical;

    my %texi_suffixes;
    foreach my $info_cursor (@texis)
    {
        my $infobase = $info_cursor;
        $infobase =~ s/\.(txi|texinfo|texi)$//;

	if ($infobase eq $info_cursor)
	{
	    # FIXME: report line number.
	    &am_error ("texinfo file `$info_cursor' has unrecognized extension");
	    next;
	}
	$texi_suffixes{$1} = 1;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	my ($out_file, $vtexi, @clean_files) =
	  &scan_texinfo_file ("$relative_dir/$info_cursor")
	    or next;
	push (@texi_cleans, @clean_files);

	if ($vtexi)
	{
	    &am_error ("`$vtexi', included in `$info_cursor', also included in `$versions{$vtexi}'")
		if (defined $versions{$vtexi});
	    $versions{$vtexi} = $info_cursor;

	    # We number the stamp-vti files.  This is doable since the
	    # actual names don't matter much.  We only number starting
	    # with the second one, so that the common case looks nice.
	    my $vti = ($done ? $done : 'vti');
	    ++$done;

	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'mdate-sh');

	    my $conf_dir;
	    if ($config_aux_dir eq '.' || $config_aux_dir eq '')
	    {
		$conf_dir = '$(srcdir)/';
	    }
	    else
	    {
		$conf_dir = $config_aux_dir;
		$conf_dir .= '/' unless $conf_dir =~ /\/$/;
	    }
	    $output_rules .= &file_contents ('texi-vers',
					     ('TEXI'  => $info_cursor,
					      'VTI'   => $vti,
					      'VTEXI' => $vtexi,
					      'MDDIR' => $conf_dir));
	}

	# If user specified file_TEXINFOS, then use that as explicit
	# dependency list.
	@texi_deps = ();
	push (@texi_deps, $info_cursor);
	# Prefix with $(srcdir) because some version of make won't
	# work if the target has it and the dependency doesn't.
	push (@texi_deps, '$(srcdir)/' . $vtexi) if $vtexi;

	my $canonical = &canonicalize ($infobase);
	if (&variable_defined ($canonical . "_TEXINFOS"))
	{
	    push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
	    &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
	}

	$output_rules .= ("\n" . $out_file . ": "
			  . join (' ', @texi_deps)
			  . "\n" . $infobase . ".dvi: "
			  . join (' ', @texi_deps)
			  . "\n");

	push (@info_deps_list, $out_file);
	push (@dvis_list, $infobase . '.dvi');
    }

    # Handle location of texinfo.tex.
    my $need_texi_file = 0;
    my $texinfodir;
    if ($cygnus_mode)
    {
        $texinfodir = '$(top_srcdir)/../texinfo';
	&define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");

    }
    elsif ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
        $texinfodir = $config_aux_dir;
	&define_variable ('TEXINFO_TEX', "$texinfodir/texinfo.tex");
	$need_texi_file = 2; # so that we require_conf_file later
    }
    elsif (&variable_defined ('TEXINFO_TEX'))
    {
	# The user defined TEXINFO_TEX so assume he knows what he is
	# doing.
        $texinfodir = ('$(srcdir)/'
		       . dirname (&variable_value ('TEXINFO_TEX')));
    }
    else
    {
        $texinfodir = '$(srcdir)';
	$need_texi_file = 1;
    }

    foreach my $txsfx (sort keys %texi_suffixes)
    {
	$output_rules .= &file_contents ('texibuild',
					 ('TEXINFODIR' => $texinfodir,
					  'SUFFIX'     => $txsfx));
    }

    my $texiclean = &pretty_print_internal ("", "\t  ", @texi_cleans);
    $output_rules .=  &file_contents ('texinfos',
				      ('TEXICLEAN' => $texiclean));

    push (@dist_targets, 'dist-info');

    if (! defined $options{'no-installinfo'})
    {
	# Make sure documentation is made and installed first.  Use
	# $(INFO_DEPS), not 'info', because otherwise recursive makes
	# get run twice during "make all".
	unshift (@all, '$(INFO_DEPS)');
    }

    &define_variable ("INFO_DEPS", join (' ', @info_deps_list));
    &define_variable ("DVIS", join (' ', @dvis_list));
    # This next isn't strictly needed now -- the places that look here
    # could easily be changed to look in info_TEXINFOS.  But this is
    # probably better, in case noinst_TEXINFOS is ever supported.
    &define_variable ("TEXINFOS", &variable_value ('info_TEXINFOS'));

    # Do some error checking.  Note that this file is not required
    # when in Cygnus mode; instead we defined TEXINFO_TEX explicitly
    # up above.
    if ($need_texi_file && ! defined $options{'no-texinfo.tex'})
    {
	if ($need_texi_file > 1)
	{
	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'texinfo.tex');
	}
	else
	{
	    &require_file_with_line ('info_TEXINFOS', $FOREIGN, 'texinfo.tex');
	}
    }
}

# Handle any man pages.
sub handle_man_pages
{
    &am_line_error ('MANS', "`MANS' is an anachronism; use `man_MANS'")
	if &variable_defined ('MANS');

    # Find all the sections in use.  We do this by first looking for
    # "standard" sections, and then looking for any additional
    # sections used in man_MANS.
    my (%sections, %vlist);
    # We handle nodist_ for uniformity.  man pages aren't distributed
    # by default so it isn't actually very important.
    foreach my $pfx ('', 'dist_', 'nodist_')
    {
	# Add more sections as needed.
	foreach my $section ('0'..'9', 'n', 'l')
	{
	    if (&variable_defined ($pfx . 'man' . $section . '_MANS'))
	    {
		$sections{$section} = 1;
		$vlist{'$(' . $pfx . 'man' . $section . '_MANS)'} = 1;

		&push_dist_common ('$(' . $pfx . 'man' . $section . '_MANS)')
		    if $pfx eq 'dist_';
	    }
	}

	if (&variable_defined ($pfx . 'man_MANS'))
	{
	    $vlist{'$(' . $pfx . 'man_MANS)'} = 1;
	    foreach (&variable_value_as_list ($pfx . 'man_MANS', 'all'))
	    {
		# A page like `foo.1c' goes into man1dir.
		if (/\.([0-9a-z])([a-z]*)$/)
		{
		    $sections{$1} = 1;
		}
	    }

	    &push_dist_common ('$(' . $pfx . 'man_MANS)')
		if $pfx eq 'dist_';
	}
    }

    return unless %sections;

    # Now for each section, generate an install and unintall rule.
    # Sort sections so output is deterministic.
    foreach my $section (sort keys %sections)
    {
	$output_rules .= &file_contents ('mans', ('SECTION' => $section));
    }

    $output_vars .= &file_contents ('mans-vars',
				    ('MANS' => join (' ', sort keys %vlist)));

    if (! defined $options{'no-installman'})
    {
	push (@all, '$(MANS)');
    }
}

# Handle DATA variables.
sub handle_data
{
    &am_install_var ('-noextra', '-candist', 'data', 'DATA',
		     'data', 'sysconf', 'sharedstate', 'localstate',
		     'pkgdata', 'noinst', 'check');
}

# Handle TAGS.
sub handle_tags
{
    my @tag_deps = ();
    if (&variable_defined ('SUBDIRS'))
    {
	$output_rules .= ("tags-recursive:\n"
			  . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
			  # Never fail here if a subdir fails; it
			  # isn't important.
			  . "\t  test \"\$\$subdir\" = . || (cd \$\$subdir"
			  . " && \$(MAKE) \$(AM_MAKEFLAGS) tags); \\\n"
			  . "\tdone\n");
	push (@tag_deps, 'tags-recursive');
	&depend ('.PHONY', 'tags-recursive');
    }

    if (&saw_sources_p (1)
	|| &variable_defined ('ETAGS_ARGS')
	|| @tag_deps)
    {
	my $config = '';
	foreach my $one_hdr (@config_headers)
	{
	    if ($relative_dir eq dirname ($one_hdr))
	    {
		# The config header is in this directory.  So require it.
		$config .= ' ' if $config;
		$config .= basename ($one_hdr);
	    }
	}
	$output_rules .= &file_contents ('tags',
					 ('CONFIG' => $config,
					  'DIRS'   => join (' ', @tag_deps)));
	&examine_variable ('TAGS_DEPENDENCIES');
    }
    elsif (&variable_defined ('TAGS_DEPENDENCIES'))
    {
	&am_line_error ('TAGS_DEPENDENCIES',
			"doesn't make sense to define `TAGS_DEPENDENCIES' without sources or `ETAGS_ARGS'");
    }
    else
    {
	# Every Makefile must define some sort of TAGS rule.
	# Otherwise, it would be possible for a top-level "make TAGS"
	# to fail because some subdirectory failed.
	$output_rules .= "tags: TAGS\nTAGS:\n\n";
    }
}

# Handle multilib support.
sub handle_multilib
{
    return unless $seen_multilib;

    $output_rules .= &file_contents ('multilib');
}


# $BOOLEAN
# &for_dist_common ($A, $B)
# -------------------------
# Subroutine for &handle_dist: sort files to dist.
#
# We put README first because it then becomes easier to make a
# Usenet-compliant shar file (in these, README must be first).
#
# FIXME: do more ordering of files here.
sub for_dist_common
{
    return 0
        if $a eq $b;
    return -1
        if $a eq 'README';
    return 1
        if $b eq 'README';
    return $a cmp $b;
}


# handle_dist ($MAKEFILE)
# -----------------------
# Handle 'dist' target.
sub handle_dist
{
    my ($makefile) = @_;

    # `make dist' isn't used in a Cygnus-style tree.
    # Omit the rules so that people don't try to use them.
    return if $cygnus_mode;

    # Set up maint_charset.
    $local_maint_charset = &variable_value ('MAINT_CHARSET')
	if &variable_defined ('MAINT_CHARSET');
    $maint_charset = $local_maint_charset
	if $relative_dir eq '.';

    if (&variable_defined ('DIST_CHARSET'))
    {
	&am_line_error ('DIST_CHARSET',
			"DIST_CHARSET defined but no MAINT_CHARSET defined")
	    if ! $local_maint_charset;
	if ($relative_dir eq '.')
	{
	    $dist_charset = &variable_value ('DIST_CHARSET')
	}
	else
	{
	    &am_line_error ('DIST_CHARSET',
			    "DIST_CHARSET can only be defined at top level");
	}
    }

    # Look for common files that should be included in distribution.
    foreach my $cfile (@common_files)
    {
	if (-f ($relative_dir . "/" . $cfile))
	{
	    &push_dist_common ($cfile);
	}
    }

    # We might copy elements from $configure_dist_common to
    # %dist_common if we think we need to.  If the file appears in our
    # directory, we would have discovered it already, so we don't
    # check that.  But if the file is in a subdir without a Makefile,
    # we want to distribute it here if we are doing `.'.  Ugly!
    if ($relative_dir eq '.')
    {
       foreach my $file (split (' ' , $configure_dist_common))
       {
           if (! &is_make_dir (dirname ($file)))
           {
               &push_dist_common ($file);
           }
       }
    }



    # Files to distributed.  Don't use &variable_value_as_list
    # as it recursively expands `$(dist_pkgdata_DATA)' etc.
    check_variable_defined_unconditionally ('DIST_COMMON');
    my @dist_common = split (' ', variable_value ('DIST_COMMON', 'TRUE'));
    @dist_common = uniq (sort for_dist_common (@dist_common));
    pretty_print ('DIST_COMMON = ', "\t", @dist_common);

    # Now that we've processed DIST_COMMON, disallow further attempts
    # to set it.
    $handle_dist_run = 1;

    # Scan EXTRA_DIST to see if we need to distribute anything from a
    # subdir.  If so, add it to the list.  I didn't want to do this
    # originally, but there were so many requests that I finally
    # relented.
    if (&variable_defined ('EXTRA_DIST'))
    {
	# FIXME: This should be fixed to work with conditionals.  That
	# will require only making the entries in %dist_dirs under the
	# appropriate condition.  This is meaningful if the nature of
	# the distribution should depend upon the configure options
	# used.
	foreach (&variable_value_as_list ('EXTRA_DIST', ''))
	{
	    next if /^\@.*\@$/;
	    next unless s,/+[^/]+$,,;
	    $dist_dirs{$_} = 1
		unless $_ eq '.';
	}
    }

    # We have to check DIST_COMMON for extra directories in case the
    # user put a source used in AC_OUTPUT into a subdir.
    foreach (&variable_value_as_list ('DIST_COMMON', 'all'))
    {
	next if /^\@.*\@$/;
	next unless s,/+[^/]+$,,;
	$dist_dirs{$_} = 1
	    unless $_ eq '.';
    }

    # Rule to check whether a distribution is viable.
    my %transform = ('DISTCHECK-HOOK' => &target_defined ('distcheck-hook'),
		     'GETTEXT'        => $seen_gettext);

    # Prepend $(distdir) to each directory given.
    my %rewritten;
    grep ($rewritten{'$(distdir)/' . $_} = 1, keys %dist_dirs);
    $transform{'DISTDIRS'} = join (' ', sort keys %rewritten);

    # If we have SUBDIRS, create all dist subdirectories and do
    # recursive build.
    if (&variable_defined ('SUBDIRS'))
    {
	# If SUBDIRS is conditionally defined, then set DIST_SUBDIRS
	# to all possible directories, and use it.  If DIST_SUBDIRS is
	# defined, just use it.
	my $dist_subdir_name;
	# Note that we check DIST_SUBDIRS first on purpose.  At least
	# one project uses so many conditional subdirectories that
	# calling variable_conditionally_defined on SUBDIRS will cause
	# automake to grow to 150Mb.  Sigh.
	if (&variable_defined ('DIST_SUBDIRS')
	    || variable_conditionally_defined ('SUBDIRS'))
	{
	    $dist_subdir_name = 'DIST_SUBDIRS';
	    if (! &variable_defined ('DIST_SUBDIRS'))
	    {
		&define_pretty_variable
		  ('DIST_SUBDIRS', '',
		   uniq (&variable_value_as_list ('SUBDIRS', 'all')));
	    }
	}
	else
	{
	    $dist_subdir_name = 'SUBDIRS';
	    # We always define this because that is what `distclean'
	    # wants.
	    &define_pretty_variable ('DIST_SUBDIRS', '', '$(SUBDIRS)');
	}

	$transform{'DIST_SUBDIR_NAME'} = $dist_subdir_name;
    }

    # If the target `dist-hook' exists, make sure it is run.  This
    # allows users to do random weird things to the distribution
    # before it is packaged up.
    push (@dist_targets, 'dist-hook')
      if &target_defined ('dist-hook');
    $transform{'DIST-TARGETS'} = join(' ', @dist_targets);

    # Defining $(DISTDIR).
    $transform{'DISTDIR'} = !&variable_defined('distdir');
    $transform{'TOP_DISTDIR'} = backname ($relative_dir);

    $output_rules .= &file_contents ('distdir', %transform);
}


# Handle auto-dependency code.
sub handle_dependencies
{
    if ($use_dependencies)
    {
	# Include auto-dep code.  Don't include it if DEP_FILES would
	# be empty.
	if (&saw_sources_p (0) && keys %dep_files)
	{
	    my $config_aux_dir_specified = ($config_aux_dir ne '.'
					    && $config_aux_dir ne '');

	    # Set $require_file_found{'depcomp'} if the depcomp file exists,
	    # before calling require_config_file on `depcomp'.  This makes
	    # require_file_internal skip its buggy existence test that would
	    # make automake fail (with `required file `lib/depcomp' not found')
	    # when AC_CONFIG_AUX_DIR is not set.  See tests/subdir4.test.
	    my $depcomp_dir = ($config_aux_dir_specified ? $config_aux_dir
			       : '.');
	    $require_file_found{'depcomp'} = 1 if -f "$depcomp_dir/depcomp";

	    # Set location of depcomp.
	    my $prefix = ($config_aux_dir_specified ? $config_aux_dir
			  : '$(top_srcdir)');

	    &define_variable ('depcomp', "\$(SHELL) $prefix/depcomp");

	    &require_config_file ($FOREIGN, 'depcomp');

	    my @deplist = sort keys %dep_files;

	    # We define this as a conditional variable because BSD
	    # make can't handle backslashes for continuing comments on
	    # the following line.
	    &define_pretty_variable ('DEP_FILES', 'AMDEP_TRUE', @deplist);

	    # Generate each `include' individually.  Irix 6 make will
	    # not properly include several files resulting from a
	    # variable expansion; generating many separate includes
	    # seems safest.
	    $output_rules .= "\n";
	    foreach my $iter (@deplist)
 	    {
		# The strange concatentation is used to avoid
		# substitutions from our own configure.
		$output_rules .= ('@AMDEP' . '_TRUE@@_am_include@ @_am_quote@'
				  . $iter . '@_am_quote@' . "\n");
	    }

	    $output_rules .= &file_contents ('depend');
	}
    }
    else
    {
	&define_variable ('depcomp', '');
    }

    foreach my $lang (values %languages)
    {
        if ($lang->autodep ne 'no')
	  {
	    add_depend2 ($lang);
	  }
    }
}

# Handle subdirectories.
sub handle_subdirs
{
    return
      unless &variable_defined ('SUBDIRS');

    # Make sure each directory mentioned in SUBDIRS actually exists.
    foreach my $dir (&variable_value_as_list ('SUBDIRS', 'all'))
    {
	# Skip directories substituted by configure.
	next if $dir =~ /^\@.*\@$/;

	if (! -d $am_relative_dir . '/' . $dir)
	{
	    &am_line_error ('SUBDIRS',
			    "required directory $am_relative_dir/$dir does not exist");
	    next;
	}

	&am_line_error ('SUBDIRS', "directory should not contain `/'")
	    if $dir =~ /\//;
    }

    $output_rules .= &file_contents ('subdirs');
    variable_pretty_output ('RECURSIVE_TARGETS', 'TRUE');
}


# ($REGEN, @DEPENDENCIES)
# &scan_aclocal_m4
# ----------------
# If aclocal.m4 creation is automated, return the list of its dependencies.
sub scan_aclocal_m4
{
    my $regen_aclocal = 0;

    return (0, ())
      unless $relative_dir eq '.';

    &examine_variable ('CONFIG_STATUS_DEPENDENCIES');
    &examine_variable ('CONFIGURE_DEPENDENCIES');

    if (-f 'aclocal.m4')
    {
	&define_variable ("ACLOCAL_M4", '$(top_srcdir)/aclocal.m4');
	&push_dist_common ('aclocal.m4');

	my $aclocal = new IO::File ("< aclocal.m4");
	if ($aclocal)
	{
	    my $line = $aclocal->getline;
	    $aclocal->close;

	    if ($line =~ 'generated automatically by aclocal')
	    {
		$regen_aclocal = 1;
	    }
	}
    }

    my @ac_deps = ();

    if (-f 'acinclude.m4')
    {
	$regen_aclocal = 1;
	push @ac_deps, 'acinclude.m4';
    }

    if (&variable_defined ('ACLOCAL_M4_SOURCES'))
    {
	push (@ac_deps, '$(ACLOCAL_M4_SOURCES)');
    }
    elsif (&variable_defined ('ACLOCAL_AMFLAGS'))
    {
	# Scan all -I directories for m4 files.  These are our
	# dependencies.
	my $examine_next = 0;
	foreach my $amdir (&variable_value_as_list ('ACLOCAL_AMFLAGS', ''))
	{
	    if ($examine_next)
	    {
		$examine_next = 0;
		if ($amdir !~ /^\// && -d $amdir)
		{
		    foreach my $ac_dep (&my_glob ($amdir . '/*.m4'))
		    {
			$ac_dep =~ s/^\.\/+//;
			push (@ac_deps, $ac_dep)
			  unless $ac_dep eq "aclocal.m4"
			    || $ac_dep eq "acinclude.m4";
		    }
		}
	    }
	    elsif ($amdir eq '-I')
	    {
		$examine_next = 1;
	    }
	}
    }

    # Note that it might be possible that aclocal.m4 doesn't exist but
    # should be auto-generated.  This case probably isn't very
    # important.

    return ($regen_aclocal, @ac_deps);
}

# Rewrite a list of input files into a form suitable to put on a
# dependency list.  The idea is that if an input file has a directory
# part the same as the current directory, then the directory part is
# simply removed.  But if the directory part is different, then
# $(top_srcdir) is prepended.  Among other things, this is used to
# generate the dependency list for the output files generated by
# AC_OUTPUT.  Consider what the dependencies should look like in this
# case:
#   AC_OUTPUT(src/out:src/in1:lib/in2)
# The first argument, ADD_SRCDIR, is 1 if $(top_srcdir) should be added.
# If 0 then files that require this addition will simply be ignored.
sub rewrite_inputs_into_dependencies
{
    my ($add_srcdir, @inputs) = @_;
    my @newinputs;

    foreach my $single (@inputs)
    {
	if (dirname ($single) eq $relative_dir)
	{
	    push (@newinputs, basename ($single));
	}
	elsif ($add_srcdir)
	{
	    push (@newinputs, '$(top_srcdir)/' . $single);
	}
    }

    return @newinputs;
}

# Handle remaking and configure stuff.
# We need the name of the input file, to do proper remaking rules.
sub handle_configure
{
    my ($local, $input, @secondary_inputs) = @_;

    my $input_base = basename ($input);
    my $local_base = basename ($local);

    my $amfile = $input_base . '.am';
    # We know we can always add '.in' because it really should be an
    # error if the .in was missing originally.
    my $infile = '$(srcdir)/' . $input_base . '.in';
    my $colon_infile = '';
    if ($local ne $input || @secondary_inputs)
    {
	$colon_infile = ':' . $input . '.in';
    }
    $colon_infile .= ':' . join (':', @secondary_inputs)
	if @secondary_inputs;

    my @rewritten = &rewrite_inputs_into_dependencies (1, @secondary_inputs);

    my ($regen_aclocal_m4, @aclocal_m4_deps) = scan_aclocal_m4 ();

    $output_rules .=
      &file_contents ('configure',
		      ('MAKEFILE'
		       => $local_base,
		       'MAKEFILE-DEPS'
		       => join (' ', @rewritten),
		       'CONFIG-MAKEFILE'
		       => ((($relative_dir eq '.') ? '$@' : '$(subdir)/$@')
			   . $colon_infile),
		       'MAKEFILE-IN'
		       => $infile,
		       'MAKEFILE-IN-DEPS'
		       => join (' ', @include_stack),
		       'MAKEFILE-AM'
		       => $amfile,
		       'STRICTNESS'
		       => $cygnus_mode ? 'cygnus' : $strictness_name,
		       'USE-DEPS'
		       => $cmdline_use_dependencies ? '' : ' --ignore-deps',
		       'MAKEFILE-AM-SOURCES'
		       =>  "$input$colon_infile",
		       'REGEN-ACLOCAL-M4'
		       => $regen_aclocal_m4,
		       'ACLOCAL_M4_DEPS'
		       => join (' ', @aclocal_m4_deps)));

    if ($relative_dir eq '.')
    {
	&push_dist_common ('acconfig.h')
	    if -f 'acconfig.h';
    }

    # If we have a configure header, require it.
    my @local_fullnames = @config_fullnames;
    my @local_names = @config_names;
    my $hdr_index = 0;
    my $distclean_config = '';
    foreach my $one_hdr (@config_headers)
    {
	my $one_fullname = shift (@local_fullnames);
	my $one_name = shift (@local_names);
	$hdr_index += 1;
	my $header_dir = dirname ($one_name);

	# If the header is in the current directory we want to build
	# the header here.  Otherwise, if we're at the topmost
	# directory and the header's directory doesn't have a
	# Makefile, then we also want to build the header.
	if ($relative_dir eq $header_dir
	    || ($relative_dir eq '.' && ! &is_make_dir ($header_dir)))
	{
	    my ($cn_sans_dir, $stamp_dir);
	    if ($relative_dir eq $header_dir)
	    {
		$cn_sans_dir = basename ($one_name);
		$stamp_dir = '';
	    }
	    else
	    {
		$cn_sans_dir = $one_name;
		if ($header_dir eq '.')
		{
		    $stamp_dir = '';
		}
		else
		{
		    $stamp_dir = $header_dir . '/';
		}
	    }

	    # Compute relative path from directory holding output
	    # header to directory holding input header.  FIXME:
	    # doesn't handle case where we have multiple inputs.
	    my $ch_sans_dir;
	    if (dirname ($one_hdr) eq $relative_dir)
	    {
		$ch_sans_dir = basename ($one_hdr);
	    }
	    else
	    {
	        $ch_sans_dir = backname ($relative_dir) . '/' . $one_hdr;
	    }

	    &require_file_with_conf_line ($config_header_line,
					  $FOREIGN, $ch_sans_dir);

	    # Header defined and in this directory.
	    my @files;
	    if (-f $one_name . '.top')
	    {
		push (@files, "${cn_sans_dir}.top");
	    }
	    if (-f $one_name . '.bot')
	    {
		push (@files, "${cn_sans_dir}.bot");
	    }

	    &push_dist_common (@files);

	    # For now, acconfig.h can only appear in the top srcdir.
	    if (-f 'acconfig.h')
	    {
	        push (@files, '$(top_srcdir)/acconfig.h');
	    }

	    my $stamp_name = 'stamp-h';
	    $stamp_name .= "${hdr_index}" if scalar (@config_headers) > 1;

            my $out_dir = dirname ($ch_sans_dir);

            $output_rules .=
	      &file_contents ('remake-hdr',
			      ('FILES'              => join (' ', @files),
			       'CONFIG_HEADER'      => $cn_sans_dir,
			       'CONFIG_HEADER_IN'   => $ch_sans_dir,
			       'CONFIG_HEADER_FULL' => $one_fullname,
			       'STAMP'            => "$stamp_dir$stamp_name",
			       'SRC_STAMP'        => "$out_dir/$stamp_name"));

	    &create ("${relative_dir}/${out_dir}/${stamp_name}.in");
	    &require_file_with_conf_line ($config_header_line, $FOREIGN,
					  "${out_dir}/${stamp_name}.in");

	    $distclean_config .= ' ' if $distclean_config;
	    $distclean_config .= $cn_sans_dir;
	}
    }

    if ($distclean_config)
    {
	$output_rules .= &file_contents ('clean-hdr',
					 ('FILES' => $distclean_config));
    }

    # Set location of mkinstalldirs.
    if ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
	&define_variable ('mkinstalldirs', ('$(SHELL) ' . $config_aux_dir
					    . '/mkinstalldirs'));
    }
    else
    {
	&define_variable ('mkinstalldirs',
			  '$(SHELL) $(top_srcdir)/mkinstalldirs');
    }

    &am_line_error ('CONFIG_HEADER',
		    "`CONFIG_HEADER' is an anachronism; now determined from `$configure_ac'")
	if &variable_defined ('CONFIG_HEADER');

    my $config_header = '';
    foreach my $one_name (@config_names)
    {
	# Generate CONFIG_HEADER define.
	my $one_hdr;
	if ($relative_dir eq dirname ($one_name))
	{
	    $one_hdr = basename ($one_name);
	}
	else
	{
	    $one_hdr = "\$(top_builddir)/${one_name}";
	}

	$config_header .= ' ' if $config_header;
	$config_header .= $one_hdr;
    }
    if ($config_header)
    {
	&define_variable ("CONFIG_HEADER", $config_header);
    }

    # Now look for other files in this directory which must be remade
    # by config.status, and generate rules for them.
    my @actual_other_files = ();
    foreach my $lfile (@other_input_files)
    {
        my ($file, $local);
	my (@inputs, @rewritten_inputs);
	my ($need_rewritten);
	if ($lfile =~ /^([^:]*):(.*)$/)
	{
	    # This is the ":" syntax of AC_OUTPUT.
	    $file = $1;
	    $local = basename ($file);
	    @inputs = split (':', $2);
	    @rewritten_inputs = &rewrite_inputs_into_dependencies (1, @inputs);
	    $need_rewritten = 1;
	}
	else
	{
	    # Normal usage.
	    $file = $lfile;
	    $local = basename ($file);
	    @inputs = ($file . '.in');
	    @rewritten_inputs =
		&rewrite_inputs_into_dependencies (1, @inputs);
	    $need_rewritten = 0;
	}

	# Make sure the dist directory for each input file is created.
	# We only have to do this at the topmost level though.  This
	# is a bit ugly but it easier than spreading out the logic,
	# especially in cases like AC_OUTPUT(foo/out:bar/in), where
	# there is no Makefile in bar/.
	if ($relative_dir eq '.')
	{
	    foreach (@inputs)
	    {
		$dist_dirs{dirname ($_)} = 1;
	    }
	}

	# We skip any automake input files, as they are handled
	# elsewhere.  We also skip files that aren't in this
	# directory.  However, if the file's directory does not have a
	# Makefile, and we are currently doing `.', then we create a
	# rule to rebuild the file in the subdir.
	next if -f $file . '.am';
	my $fd = dirname ($file);
	if ($fd ne $relative_dir)
	{
	    if ($relative_dir eq '.' && ! &is_make_dir ($fd))
	    {
		$local = $file;
	    }
	    else
	    {
		next;
	    }
	}

	# Some users have been tempted to put `stamp-h' in the
	# AC_OUTPUT line.  This won't do the right thing, so we
	# explicitly fail here.
	if ($local eq 'stamp-h')
	{
	    # FIXME: allow real filename.
	    &am_conf_error ($configure_ac, $ac_output_line,
			    'stamp-h should not appear in AC_OUTPUT');
	    next;
	}

	$output_rules .= ($local . ': '
			  . '$(top_builddir)/config.status '
			  . join (' ', @rewritten_inputs) . "\n"
			  . "\t"
			  . 'cd $(top_builddir) && CONFIG_FILES='
			  . ($relative_dir eq '.' ? '' : '$(subdir)/')
   			  . '$@' . ($need_rewritten
				    ? (':' . join (':', @inputs))
				    : '')
			  . ' CONFIG_HEADERS= CONFIG_LINKS= $(SHELL) ./config.status'
			  . "\n");
	push (@actual_other_files, $local);

	# Require all input files.
	&require_file_with_conf_line ($ac_output_line, $FOREIGN,
				      &rewrite_inputs_into_dependencies (0, @inputs));
    }

    # These files get removed by "make clean".
    &define_pretty_variable ('CONFIG_CLEAN_FILES', '', @actual_other_files);
}

# Handle C headers.
sub handle_headers
{
    my @r = &am_install_var ('-defaultdist', 'header', 'HEADERS', 'include',
			     'oldinclude', 'pkginclude',
			     'noinst', 'check');
    foreach (@r)
    {
	next unless /\.(.*)$/;
	&saw_extension ($1);
    }
}

sub handle_gettext
{
    return if ! $seen_gettext || $relative_dir ne '.';

    if (! &variable_defined ('SUBDIRS'))
    {
	&am_conf_error
	    ("AM_GNU_GETTEXT used but SUBDIRS not defined");
	return;
    }

    my @subdirs = &variable_value_as_list ('SUBDIRS', 'all');
    &am_line_error ('SUBDIRS',
		    "AM_GNU_GETTEXT used but `po' not in SUBDIRS")
	if ! grep ('po', @subdirs);
    &am_line_error ('SUBDIRS',
		    "AM_GNU_GETTEXT used but `intl' not in SUBDIRS")
	if ! grep ('intl', @subdirs);

    &require_file_with_conf_line ($ac_gettext_line, $GNU, 'ABOUT-NLS');

    # Ensure that each language in ALL_LINGUAS has a .po file, and
    # each po file is mentioned in ALL_LINGUAS.
    if ($seen_linguas)
    {
	my %linguas = ();
	grep ($linguas{$_} = 1, split (' ', $all_linguas));

	foreach (<po/*.po>)
	{
	    s/^po\///;
	    s/\.po$//;

	    &am_line_error ($all_linguas_line,
			    ("po/$_.po exists but `$_' not in `ALL_LINGUAS'"))
		if ! $linguas{$_};
	}

	foreach (keys %linguas)
	{
	    &am_line_error ($all_linguas_line,
			    "$_ in `ALL_LINGUAS' but po/$_.po does not exist")
		if ! -f "po/$_.po";
	}
    }
    else
    {
	&am_error ("AM_GNU_GETTEXT in `$configure_ac' but `ALL_LINGUAS' not defined");
    }
}

# Handle footer elements.
sub handle_footer
{
    if (variable_value ('SOURCES'))
    {
	# NOTE don't use define_pretty_variable here, because
	# $contents{...} is already defined.
	$output_vars .= 'SOURCES = ' . variable_value ('SOURCES') . "\n";
    }
    if (variable_value ('OBJECTS'))
    {
	# NOTE don't use define_pretty_variable here, because
	# $contents{...} is already defined.
	$output_vars .= 'OBJECTS = ' . variable_value ('OBJECTS') . "\n";
    }
    if (variable_value ('SOURCES') || variable_value ('OBJECTS'))
    {
	$output_vars .= "\n";
    }

    if (&target_defined ('.SUFFIXES'))
    {
	&am_line_error ('.SUFFIXES',
			"use variable `SUFFIXES', not target `.SUFFIXES'");
    }

    # Note: AIX 4.1 /bin/make will fail if any suffix rule appears
    # before .SUFFIXES.  So we make sure that .SUFFIXES appears before
    # anything else, by sticking it right after the default: target.
    $output_header .= ".SUFFIXES:\n";
    if (@suffixes || &variable_defined ('SUFFIXES'))
    {
	# Make sure suffixes has unique elements.  Sort them to ensure
	# the output remains consistent.  However, $(SUFFIXES) is
	# always at the start of the list, unsorted.  This is done
	# because make will choose rules depending on the ordering of
	# suffixes, and this lets the user have some control.  Push
	# actual suffixes, and not $(SUFFIXES).  Some versions of make
	# do not like variable substitutions on the .SUFFIXES line.
	my @user_suffixes = (&variable_defined ('SUFFIXES')
			     ? &variable_value_as_list ('SUFFIXES', '')
			     : ());

	my %suffixes;
	grep ($suffixes{$_} = 1, @suffixes);
	delete @suffixes{@user_suffixes};

	$output_header .= (".SUFFIXES: "
			   . join (' ', @user_suffixes, sort keys %suffixes)
			   . "\n");
    }
    $output_trailer .= &file_contents ('footer');
}

# Deal with installdirs target.
sub handle_installdirs ()
{
    $output_rules .=
      &file_contents ('install',
		      ('_am_installdirs'
		       => variable_value ('_am_installdirs') || ''));
}


# Deal with all and all-am.
sub handle_all ($)
{
    my ($makefile) = @_;

    # Output `all-am'.

    # Put this at the beginning for the sake of non-GNU makes.  This
    # is still wrong if these makes can run parallel jobs.  But it is
    # right enough.
    unshift (@all, basename ($makefile));

    foreach my $one_name (@config_names)
    {
	push (@all, basename ($one_name))
	    if dirname ($one_name) eq $relative_dir;
    }

    # Install `all' hooks.
    if (&target_defined ("all-local"))
    {
      push (@all, "all-local");
      &depend ('.PHONY', "all-local");
    }

    &pretty_print_rule ("all-am:", "\t\t", @all);
    &depend ('.PHONY', 'all-am', 'all');


    # Output `all'.

    my @local_headers = ();
    push @local_headers, '$(BUILT_SOURCES)'
      if &variable_defined ('BUILT_SOURCES');
    foreach my $one_name (@config_names)
      {
	push @local_headers, basename ($one_name)
	  if dirname ($one_name) eq $relative_dir;
      }

    if (@local_headers)
      {
	# We need to make sure config.h is built before we recurse.
	# We also want to make sure that built sources are built
	# before any ordinary `all' targets are run.  We can't do this
	# by changing the order of dependencies to the "all" because
	# that breaks when using parallel makes.  Instead we handle
	# things explicitly.
	$output_all .= ("all: " . join (' ', @local_headers)
			. "\n\t"
			. '$(MAKE) $(AM_MAKEFLAGS) '
			. (&variable_defined ('SUBDIRS')
			   ? 'all-recursive' : 'all-am')
			. "\n\n");
      }
    else
      {
	$output_all .= "all: " . (&variable_defined ('SUBDIRS')
				  ? 'all-recursive' : 'all-am') . "\n\n";
      }
}


# Handle check merge target specially.
sub do_check_merge_target
{
    if (&target_defined ('check-local'))
    {
	# User defined local form of target.  So include it.
	push (@check_tests, 'check-local');
	&depend ('.PHONY', 'check-local');
    }

    # In --cygnus mode, check doesn't depend on all.
    if ($cygnus_mode)
    {
	# Just run the local check rules.
	&pretty_print_rule ('check-am:', "\t\t", @check);
    }
    else
    {
	# The check target must depend on the local equivalent of
	# `all', to ensure all the primary targets are built.  Then it
	# must build the local check rules.
	$output_rules .= "check-am: all-am\n";
	&pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
			    @check)
	    if @check;
    }
    &pretty_print_rule ("\t\$(MAKE) \$(AM_MAKEFLAGS)", "\t  ",
			@check_tests)
	if @check_tests;

    &depend ('.PHONY', 'check', 'check-am');
    $output_rules .= ("check: "
		      . (&variable_defined ('SUBDIRS')
			 ? 'check-recursive' : 'check-am')
		      . "\n");
}

# Handle all 'clean' targets.
sub handle_clean
{
    my %transform;

    # Don't include `MAINTAINER'; it is handled specially below.
    foreach my $name ('MOSTLY', '', 'DIST')
    {
      $transform{"${name}CLEAN"} = &variable_defined ("${name}CLEANFILES");
    }

    # Built sources are automatically removed by maintainer-clean.
    push (@maintainer_clean_files, '$(BUILT_SOURCES)')
	if &variable_defined ('BUILT_SOURCES');
    push (@maintainer_clean_files, '$(MAINTAINERCLEANFILES)')
	if &variable_defined ('MAINTAINERCLEANFILES');

    $output_rules .= &file_contents ('clean',
				     (%transform,
				      'MCFILES'
				      # Join with no space to avoid
				      # spurious `test -z' success at
				      # runtime.
				      => join ('', @maintainer_clean_files),
				      'MFILES'
				      # A space is required in the join here.
				      => join (' ', @maintainer_clean_files)));
}


# &depend ($CATEGORY, @DEPENDENDEES)
# ----------------------------------
# The target $CATEGORY depends on @DEPENDENDEES.
sub depend
{
    my ($category, @dependendees) = @_;
    {
      push (@{$dependencies{$category}}, @dependendees);
    }
}


# &target_cmp ($A, $B)
# --------------------
# Subroutine for &handle_factored_dependencies to let `.PHONY' be last.
sub target_cmp
{
    return 0
        if $a eq $b;
    return -1
        if $b eq '.PHONY';
    return 1
        if $a eq '.PHONY';
    return $a cmp $b;
}


# &handle_factored_dependencies ()
# --------------------------------
# Handle everything related to gathered targets.
sub handle_factored_dependencies
{
    # Reject bad hooks.
    foreach my $utarg ('uninstall-data-local', 'uninstall-data-hook',
		       'uninstall-exec-local', 'uninstall-exec-hook')
    {
	if (&target_defined ($utarg))
	{
	    my $x = $utarg;
	    $x =~ s/(data|exec)-//;
	    &am_line_error ($utarg, "use `$x', not `$utarg'");
	}
    }

    if (&target_defined ('install-local'))
    {
	&am_line_error ('install-local',
			"use `install-data-local' or `install-exec-local', "
			. "not `install-local'");
    }

    if (!defined $options{'no-installinfo'}
	&& &target_defined ('install-info-local'))
    {
	&am_line_error ('install-info-local',
			"`install-info-local' target defined but "
			. "`no-installinfo' option not in use");
    }

    # Install the -local hooks.
    foreach (keys %dependencies)
    {
      # Hooks are installed on the -am targets.
      s/-am$// or next;
      if (&target_defined ("$_-local"))
	{
	  depend ("$_-am", "$_-local");
	  &depend ('.PHONY', "$_-local");
	}
    }

    # Install the -hook hooks.
    # FIXME: Why not be as liberal as we are with -local hooks?
    foreach ('install-exec', 'install-data')
    {
      if (&target_defined ("$_-hook"))
	{
	  $actions{"$_-am"} .=
	    ("\t\@\$(NORMAL_INSTALL)\n"
	     . "\t" . '$(MAKE) $(AM_MAKEFLAGS) ' . "$_-hook\n");
	}
    }

    # All the required targets are phony.
    grep { &depend ('.PHONY', $_) } keys %required_targets;

    # Actually output gathered targets.
    foreach (sort target_cmp keys %dependencies)
    {
        # If there is nothing about this guy, skip it.
        next
	  unless (@{$dependencies{$_}}
		  || $actions{$_}
		  || $required_targets{$_});
        &pretty_print_rule ("$_:", "\t",
			    uniq (sort @{$dependencies{$_}}));
	$output_rules .= $actions{$_}
	  if defined $actions{$_};
        $output_rules .= "\n";
    }
}


# &handle_tests_dejagnu ()
# ------------------------
sub handle_tests_dejagnu
{
    push (@check_tests, 'check-DEJAGNU');

    # Only create site.exp rule if user hasn't already written one.
    $output_rules .=
      &file_contents ('dejagnu',
		      ('SITE-EXP' => ! &target_defined ('site.exp'),
		       'BUILD'    => $seen_canonical == $AC_CANONICAL_SYSTEM,
		       'HOST'     => $seen_canonical,
		       'TARGET'   => $seen_canonical == $AC_CANONICAL_SYSTEM));
}


# Handle TESTS variable and other checks.
sub handle_tests
{
    if (defined $options{'dejagnu'})
    {
        &handle_tests_dejagnu;
    }
    else
    {
	foreach my $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
	{
	    &am_line_error ($c,
			    "`$c' defined but `dejagnu' not in `AUTOMAKE_OPTIONS'")
	      if &variable_defined ($c);
	}
    }

    if (&variable_defined ('TESTS'))
    {
	push (@check_tests, 'check-TESTS');
	$output_rules .= &file_contents ('check');
    }
}

# Handle Emacs Lisp.
sub handle_emacs_lisp
{
    my @elfiles = &am_install_var ('-candist', 'lisp', 'LISP',
				   'lisp', 'noinst');

    return if ! @elfiles;

    # Generate .elc files.
    grep ($_ .= 'c', @elfiles);
    &define_pretty_variable ('ELCFILES', '', @elfiles);

    push (@all, '$(ELCFILES)');

    &am_error ("`lisp_LISP' defined but `AM_PATH_LISPDIR' not in `$configure_ac'")
      if ! $seen_lispdir && &variable_defined ('lisp_LISP');

    &require_file_with_conf_line ('AM_PATH_LISPDIR', $FOREIGN, 'elisp-comp');
}

# Handle Python
sub handle_python
{
    my @pyfiles = &am_install_var ('-defaultdist', 'python', 'PYTHON',
				   'python', 'noinst');
    return if ! @pyfiles;

    # Found some python.
    &am_error ("`python_PYTHON' defined but `AM_CHECK_PYTHON' not in `$configure_ac'")
	if ! $seen_pythondir && &variable_defined ('python_PYTHON');

    &require_file_with_conf_line ('AM_CHECK_PYTHON', $FOREIGN, 'py_comp');
}

# Handle Java.
sub handle_java
{
    my @sourcelist = &am_install_var ('-candist',
				      'java', 'JAVA',
				      'java', 'noinst', 'check');
    return if ! @sourcelist;

    my %valid = &am_primary_prefixes ('JAVA', 1,
				      'java', 'noinst', 'check');

    my $dir;
    foreach my $curs (keys %valid)
    {
	if (! &variable_defined ($curs . '_JAVA') || $curs eq 'EXTRA')
	{
	    next;
	}

	if (defined $dir)
	{
	    &am_line_error ($curs . '_JAVA',
			    "multiple _JAVA primaries in use");
	}
	$dir = $curs;
    }

    push (@all, 'class' . $dir . '.stamp');
}


# Handle some of the minor options.
sub handle_minor_options
{
    if (defined $options{'readme-alpha'})
    {
	if ($relative_dir eq '.')
	{
	    if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
	    {
		# FIXME: allow real filename.
		&am_conf_line_error ($configure_ac,
				     $package_version_line,
				     "version `$package_version' doesn't follow Gnits standards");
	    }
	    elsif (defined $1 && -f 'README-alpha')
	    {
		# This means we have an alpha release.  See
		# GNITS_VERSION_PATTERN for details.
		&require_file ($FOREIGN, 'README-alpha');
	    }
	}
    }
}

################################################################

my %make_list;
my @make_input_list;
# &scan_autoconf_config_files ($CONFIG-FILES)
# -------------------------------------------
# Study $CONFIG-FILES which is the first argument to AC_CONFIG_FILES
# (or AC_OUTPUT).
sub scan_autoconf_config_files
{
    my ($config_files) = @_;
    # Look at potential Makefile.am's.
    foreach (split ' ', $config_files)
    {
        # Must skip empty string for Perl 4.
        next if $_ eq "\\" || $_ eq '';

        # Handle $local:$input syntax.  Note that we ignore
        # every input file past the first, though we keep
        # those around for later.
        my ($local, $input, @rest) = split (/:/);
        if (! $input)
        {
            $input = $local;
        }
        else
        {
            # FIXME: should be error if .in is missing.
            $input =~ s/\.in$//;
        }

        if (-f $input . '.am')
        {
            # We have a file that automake should generate.
            push (@make_input_list, $input);
            $make_list{$input} = join (':', ($local, @rest));
        }
        else
        {
            # We have a file that automake should cause to be
            # rebuilt, but shouldn't generate itself.
            push (@other_input_files, $_);
        }
    }
}


# &scan_autoconf_traces ($FILENAME)
# ---------------------------------
# FIXME: For the time being, we don't care about the FILENAME.
sub scan_autoconf_traces
{
    my ($filename) = @_;

    my $traces = "$ENV{amtraces} ";

    $traces .= ' -t AC_CONFIG_FILES';
    $traces .= ' -t AC_LIBSOURCE';
    $traces .= ' -t AC_SUBST';

    my $tracefh = new IO::File ("$traces |");
    if (! $tracefh)
    {
	die "$me: couldn't open `$traces': $!\n";
    }
    print "$me: reading $traces\n" if $verbose;

    while ($_ = $tracefh->getline)
    {
        chomp;
        my ($file, $line, $macro, @args) = split /:/;
	my $here = "$file:$line";

	# Alphabetical ordering please.
        if ($macro eq 'AC_CONFIG_FILES')
	{
	    # Look at potential Makefile.am's.
	    &scan_autoconf_config_files ($args[0]);
	}
        elsif ($macro eq 'AC_LIBSOURCE')
	{
	    my $source = "$args[0].c";
	    # We should actually also `close' the sources: getopt.c
	    # wants getopt.h etc.  But actually it should be done in the
	    # macro itself, i.e., we have to first fix Autoconf to extend
	    # _AC_LIBOBJ_DECL and use it the in various macros.
	    if (!defined $libsources{$source})
	        {
		    print STDERR "traces: discovered $source\n";
		    $libsources{$source} = $here;
	        }
	}
        elsif ($macro eq 'AC_SUBST')
	{
	    if (!defined $configure_vars{$args[0]})
	        {
		    print STDERR "traces: discovered AC_SUBST($args[0])\n";
		    $configure_vars{$args[0]} = $here;
	        }
	}
    }

    $tracefh->close
	|| die "$me: close: $traces: $!\n";
}


# &scan_one_autoconf_file ($FILENAME)
# -----------------------------------
# Scan one file for interesting things.  Subroutine of
# &scan_autoconf_files.
sub scan_one_autoconf_file
{
    my ($filename) = @_;

    my $configfh = new IO::File ("< $filename");
    if (! $configfh)
    {
	die "$me: couldn't open `$filename': $!\n";
    }
    print "$me: reading $filename\n" if $verbose;

    my ($in_ac_output, $in_ac_replace) = (0, 0);
    while ($_ = $configfh->getline)
    {
	# Remove comments from current line.
	s/\bdnl\b.*$//;
	s/\#.*$//;

	# Skip macro definitions.  Otherwise we might be confused into
	# thinking that a macro that was only defined was actually
	# used.
	next if /AC_DEFUN/;

	# Follow includes.  This is a weirdness commonly in use at
	# Cygnus and hopefully nowhere else.
	if (/sinclude\((.*)\)/ && -f $1)
	{
	    # $_ being local, if we don't preserve it, when coming
	    # back we will have $_ undefined, which is bad for the
	    # the rest of this routine.
	    my $underscore = $_;
	    &scan_one_autoconf_file ($1);
	    $_ = $underscore;
	}

	# Populate libobjs array.
	if (/AC_FUNC_ALLOCA/)
	{
	    $libsources{'alloca.c'} = 1;
	}
	elsif (/AC_FUNC_GETLOADAVG/)
	{
	    $libsources{'getloadavg.c'} = 1;
	}
	elsif (/AC_FUNC_MEMCMP/)
	{
	    $libsources{'memcmp.c'} = 1;
	}
	elsif (/AC_STRUCT_ST_BLOCKS/)
	{
	    $libsources{'fileblocks.c'} = 1;
	}
	elsif (/A[CM]_REPLACE_GNU_GETOPT/)
	{
	    $libsources{'getopt.c'} = 1;
	    $libsources{'getopt1.c'} = 1;
	}
	elsif (/AM_FUNC_STRTOD/)
	{
	    $libsources{'strtod.c'} = 1;
	}
	elsif (/AM_WITH_REGEX/)
	{
	    $libsources{'rx.c'} = 1;
	    $libsources{'rx.h'} = 1;
	    $libsources{'regex.c'} = 1;
	    $libsources{'regex.h'} = 1;
	}
	elsif (/AC_FUNC_MKTIME/)
	{
	    $libsources{'mktime.c'} = 1;
	}
	elsif (/AM_FUNC_ERROR_AT_LINE/)
	{
	    $libsources{'error.c'} = 1;
	    $libsources{'error.h'} = 1;
	}
	elsif (/AM_FUNC_OBSTACK/)
	{
	    $libsources{'obstack.c'} = 1;
	    $libsources{'obstack.h'} = 1;
	}
	elsif (/LIBOBJS="(.*)\s+\$LIBOBJS"/
	       || /LIBOBJS="\$LIBOBJS\s+(.*)"/)
	{
	    foreach my $libobj_iter (split (' ', $1))
	    {
		if ($libobj_iter =~ /^(.*)\.o(bj)?$/
		    || $libobj_iter =~ /^(.*)\.\$ac_objext$/
		    || $libobj_iter =~ /^(.*)\.\$\{ac_objext\}$/)
		{
		    $libsources{$1 . '.c'} = 1;
		}
	    }
	}
	elsif (/AC_LIBOBJ\(([^)]+)\)/)
	{
	    $libsources{"$1.c"} = 1;
	}

	if (! $in_ac_replace && s/AC_REPLACE_FUNCS\s*\(\[?//)
	{
	    $in_ac_replace = 1;
	}
	if ($in_ac_replace)
	{
	    $in_ac_replace = 0 if s/[\]\)].*$//;
	    # Remove trailing backslash.
	    s/\\$//;
	    foreach (split)
	    {
		# Need to skip empty elements for Perl 4.
		next if $_ eq '';
		$libsources{$_ . '.c'} = 1;
	    }
	}

	if (/$obsolete_rx/o)
	{
	    my $hint = '';
	    if ($obsolete_macros{$1} ne '')
	    {
		$hint = '; ' . $obsolete_macros{$1};
	    }
	    &am_conf_line_error ($filename, $., "`$1' is obsolete$hint");
	}

	# Process the AC_OUTPUT and AC_CONFIG_FILES macros.
	if (! $in_ac_output && s/AC_(OUTPUT|CONFIG_FILES)\s*\(\[?//)
	{
	    $in_ac_output = 1;
	    $ac_output_line = $.;
	}
	if ($in_ac_output)
	{
	    my $closing = 0;
	    if (s/[\]\),].*$//)
	    {
		$in_ac_output = 0;
		$closing = 1;
	    }

	    # Look at potential Makefile.am's.
	    &scan_autoconf_config_files ($_);

	    if ($closing && @make_input_list == 0 && @other_input_files == 0)
	    {
		&am_conf_line_error ($filename, $ac_output_line,
				     "No files mentioned in `AC_OUTPUT'");
		exit 1;
	    }
	}

	if (/$AC_CONFIG_AUX_DIR_PATTERN/o)
	{
	    @config_aux_path = &unquote_m4_arg ($1);
	}

	# Check for ansi2knr.
	$am_c_prototypes = 1 if /AM_C_PROTOTYPES/;

	# Check for exe extension stuff.
	if (/AC_EXEEXT/)
	{
	    $seen_exeext = 1;
	    $configure_vars{'EXEEXT'} = $filename . ':' . $.;
	}

	if (/AC_OBJEXT/)
	{
	    $seen_objext = 1;
	    $configure_vars{'OBJEXT'} = $filename . ':' . $.;
	}

	# Check for `-c -o' code.
	$seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;

	# Check for NLS support.
	if (/AM_GNU_GETTEXT/)
	{
	    $seen_gettext = 1;
	    $ac_gettext_line = $.;
	}

        # Look for ALL_LINGUAS.
        if (/ALL_LINGUAS="(.*)"$/ || /ALL_LINGUAS=(.*)$/)
	{
	    $seen_linguas = 1;
	    $all_linguas = $1;
	    $all_linguas_line = $.;
	}

	# Handle configuration headers.  A config header of `[$1]'
	# means we are actually scanning AM_CONFIG_HEADER from
	# aclocal.m4.
	if (/A([CM])_CONFIG_HEADERS?\s*\((.*)\)/
	    && $2 ne '[$1]')
	{
	    &am_conf_line_error
 		($filename, $., "`automake requires `AM_CONFIG_HEADER', not `AC_CONFIG_HEADER'")
 		    if $1 eq 'C';

	    $config_header_line = $.;
	    foreach my $one_hdr (split (' ', &unquote_m4_arg ($2)))
	    {
		push (@config_fullnames, $one_hdr);
		if ($one_hdr =~ /^([^:]+):(.+)$/)
		{
		    push (@config_names, $1);
		    push (@config_headers, $2);
		}
		else
		{
		    push (@config_names, $one_hdr);
		    push (@config_headers, $one_hdr . '.in');
		}
	    }
	}

        # Handle AC_CANONICAL_*.  Always allow upgrading to
        # AC_CANONICAL_SYSTEM, but never downgrading.
	$seen_canonical = $AC_CANONICAL_HOST
	    if ! $seen_canonical
		&& (/AC_CANONICAL_HOST/ || /AC_CHECK_TOOL/);
        $seen_canonical = $AC_CANONICAL_SYSTEM if /AC_CANONICAL_SYSTEM/;

        # If using X, include some extra variable definitions.  NOTE
        # we don't want to force these into CFLAGS or anything,
        # because not all programs will necessarily use X.
	if (/AC_PATH_XTRA/)
	  {
	    foreach my $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS',
			     'X_PRE_LIBS')
	      {
		$configure_vars{$var} = $filename . ':' . $.
	      }
	  }

        # This macro handles several different things.
        if (/$AM_INIT_AUTOMAKE_PATTERN/o)
	{
	    ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
	    $package_version_line = $.;
	    $seen_init_automake = 1;
	}

	if (/AM_PROG_LEX/)
	{
	    $configure_vars{'LEX'} = $filename . ':' . $.;
	    $seen_decl_yytext = 1;
	}
	if (/AC_DECL_YYTEXT/ && $filename =~ /configure\.(ac|in)$/)
	{
	    &am_conf_line_warning ($filename, $., "`AC_DECL_YYTEXT' is covered by `AM_PROG_LEX'");
	}
	if (/AC_PROG_LEX/ && $filename =~ /configure\.(ac|in)$/)
	{
 	    &am_conf_line_warning ($filename, $., "automake requires `AM_PROG_LEX', not `AC_PROG_LEX'");
	}

	if (/AC_PROG_(F77|YACC|RANLIB|CC|CXXCPP|CXX|LEX|AWK|CPP|LN_S)/)
	{
	    $configure_vars{$1} = $filename . ':' . $.;
	}
	if (/$AC_CHECK_PATTERN/o)
	{
	    $configure_vars{$3} = $filename . ':' . $.;
	}
	if (/$AM_MISSING_PATTERN/o
	    && $1 ne 'ACLOCAL'
	    && $1 ne 'AUTOCONF'
	    && $1 ne 'AUTOMAKE'
	    && $1 ne 'AUTOHEADER'
	    # AM_INIT_AUTOMAKE is AM_MISSING_PROG'ing MAKEINFO.  But
	    # we handle it elsewhere.
	    && $1 ne 'MAKEINFO')
	{
	    $configure_vars{$1} = $filename . ':' . $.;
	}

	# Explicitly avoid ANSI2KNR -- we AC_SUBST that in protos.m4,
	# but later define it elsewhere.  This is pretty hacky.  We
	# also explicitly avoid INSTALL_SCRIPT and some other
	# variables because they are defined in header-vars.am.
	# FIXME.
	if (/$AC_SUBST_PATTERN/o
	    && $1 ne 'ANSI2KNR'
	    && $1 ne 'INSTALL_SCRIPT'
	    && $1 ne 'INSTALL_DATA')
	{
	    $configure_vars{$1} = $filename . ':' . $.;
	}

        $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
	if (/AM_MAINTAINER_MODE/)
	{
	    $seen_maint_mode = 1;
	    $configure_cond{'MAINTAINER_MODE'} = 1;
	}

        $seen_lispdir = 1 if /AM_PATH_LISPDIR/;

        if (/AM_PATH_PYTHON/)
	  {
	    $seen_pythondir = 1;
	    $configure_vars{'pythondir'} = $filename . ':' . $.;
	    $configure_vars{'PYTHON'} = $filename . ':' . $.;
	  }

        if (/A(C|M)_PROG_LIBTOOL/)
	{
	    # We're not ready for this yet.  People still use a
	    # libtool with no AC_PROG_LIBTOOL.  Once that is the
	    # dominant version we can reenable this code -- but next
	    # time by mentioning the macro in %obsolete_macros, both
	    # here and in aclocal.in.

	    # if (/AM_PROG_LIBTOOL/)
	    # {
	    # 	&am_conf_line_warning ($filename, $., "`AM_PROG_LIBTOOL' is obsolete, use `AC_PROG_LIBTOOL' instead");
	    # }
	    $seen_libtool = 1;
	    $libtool_line = $.;
	    $configure_vars{'LIBTOOL'} = $filename . ':' . $.;
	    $configure_vars{'RANLIB'} = $filename . ':' . $.;
	    $configure_vars{'CC'} = $filename . ':' . $.;
	    # AC_PROG_LIBTOOL runs AC_CANONICAL_HOST.  Make sure we
	    # never downgrade (if we've seen AC_CANONICAL_SYSTEM).
	    $seen_canonical = $AC_CANONICAL_HOST if ! $seen_canonical;
	}

	$seen_multilib = 1 if (/AM_ENABLE_MULTILIB/);

	if (/$AM_CONDITIONAL_PATTERN/o)
	{
	    $configure_cond{$1} = 1;
	}

	# Check for Fortran 77 intrinsic and run-time libraries.
	if (/AC_F77_LIBRARY_LDFLAGS/)
	{
	    $configure_vars{'FLIBS'} = $filename . ':' . $.;
	}
    }

    $configfh->close;
}


# &scan_autoconf_files ()
# -----------------------
# Check whether we use `configure.ac' or `configure.in'.
# Scan it (and possibly `aclocal.m4') for interesting things.
# We must scan aclocal.m4 because there might be AC_SUBSTs and such there.
sub scan_autoconf_files
{
    # Reinitialize libsources here.  This isn't really necessary,
    # since we currently assume there is only one configure.ac.  But
    # that won't always be the case.
    %libsources = ();

    warn "$me: both `configure.ac' and `configure.in' present:"
         . " ignoring `configure.in'\n"
        if -f 'configure.ac' && -f 'configure.in';
    $configure_ac = 'configure.in'
        if -f 'configure.in';
    $configure_ac = 'configure.ac'
        if -f 'configure.ac';
    die "$me: `configure.ac' or `configure.in' is required\n"
        if !$configure_ac;

    &scan_one_autoconf_file ($configure_ac);
    &scan_one_autoconf_file ('aclocal.m4')
	if -f 'aclocal.m4';

    if (defined $ENV{'amtraces'})
    {
        warn '$me: Autoconf traces is an experimental feature';
        warn '$me: use at your own risks';

        &scan_autoconf_traces ($configure_ac);
    }

    # Set input and output files if not specified by user.
    if (! @input_files)
    {
	@input_files = @make_input_list;
	%output_files = %make_list;
    }

    @configure_input_files = @make_input_list;

    &am_conf_error ("`AM_INIT_AUTOMAKE' must be used")
	if ! $seen_init_automake;

    # Look for some files we need.  Always check for these.  This
    # check must be done for every run, even those where we are only
    # looking at a subdir Makefile.  We must set relative_dir so that
    # the file-finding machinery works.
    # FIXME: Is this broken because it needs dynamic scopes.
    # My tests seems to show it's not the case.
    $relative_dir = '.';
    &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs', 'missing');
    &am_error ("`install.sh' is an anachronism; use `install-sh' instead")
        if -f $config_aux_path[0] . '/install.sh';

    &require_config_file ($FOREIGN, 'py-compile')
	if $seen_pythondir;

    # Preserve dist_common for later.
    $configure_dist_common = variable_value ('DIST_COMMON', 'TRUE');
}

################################################################

# Set up for Cygnus mode.
sub check_cygnus
{
    return unless $cygnus_mode;

    &set_strictness ('foreign');
    $options{'no-installinfo'} = 1;
    $options{'no-dependencies'} = 1;
    $use_dependencies = 0;

    if (! $seen_maint_mode)
    {
	&am_conf_error ("`AM_MAINTAINER_MODE' required when --cygnus specified");
    }
}

# Do any extra checking for GNU standards.
sub check_gnu_standards
{
    if ($relative_dir eq '.')
    {
	# In top level (or only) directory.
	&require_file ($GNU, 'INSTALL', 'NEWS', 'README', 'COPYING',
		       'AUTHORS', 'ChangeLog');
    }

    if ($strictness >= $GNU
	&& defined $options{'no-installman'})
    {
	&am_line_error ('AUTOMAKE_OPTIONS',
			"option `no-installman' disallowed by GNU standards");
    }

    if ($strictness >= $GNU
	&& defined $options{'no-installinfo'})
    {
	&am_line_error ('AUTOMAKE_OPTIONS',
			"option `no-installinfo' disallowed by GNU standards");
    }
}

# Do any extra checking for GNITS standards.
sub check_gnits_standards
{
    if ($relative_dir eq '.')
    {
	# In top level (or only) directory.
	&require_file ($GNITS, 'THANKS');
    }
}

################################################################
#
# Functions to handle files of each language.

# Each `lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
# simple formula: Return value is $LANG_SUBDIR if the resulting object
# file should be in a subdir if the source file is, $LANG_PROCESS if
# file is to be dealt with, $LANG_IGNORE otherwise.

# Much of the actual processing is handled in
# handle_single_transform_list.  These functions exist so that
# auxiliary information can be recorded for a later cleanup pass.
# Note that the calls to these functions are computed, so don't bother
# searching for their precise names in the source.

# This is just a convenience function that can be used to determine
# when a subdir object should be used.
sub lang_sub_obj
{
    return defined $options{'subdir-objects'} ? $LANG_SUBDIR : $LANG_PROCESS;
}

# Rewrite a single C source file.
sub lang_c_rewrite
{
    my ($directory, $base, $ext) = @_;

    if (defined $options{'ansi2knr'} && $base =~ /_$/)
    {
	# FIXME: include line number in error.
	&am_error ("C source file `$base.c' would be deleted by ansi2knr rules");
    }

    my $r = $LANG_PROCESS;
    if (defined $options{'subdir-objects'})
    {
	$r = $LANG_SUBDIR;
	$base = $directory . '/' . $base;

	if (! $seen_cc_c_o)
	{
	    # Only give error once.
	    $seen_cc_c_o = 1;
	    # FIXME: line number.
	    &am_error ("C objects in subdir but `AM_PROG_CC_C_O' not in `$configure_ac'");
	}

	&require_file ($FOREIGN, 'compile')
	    if $relative_dir eq '.';
    }

    $de_ansi_files{$base} = 1;
    return $r;
}

# Rewrite a single C++ source file.
sub lang_cxx_rewrite
{
    return &lang_sub_obj;
}

# Rewrite a single header file.
sub lang_header_rewrite
{
    # Header files are simply ignored.
    return $LANG_IGNORE;
}

# Rewrite a single yacc file.
sub lang_yacc_rewrite
{
    my ($directory, $base, $ext) = @_;

    my $r = &lang_c_rewrite ($directory, $base, $ext);
    my $pfx = '';
    if ($r == $LANG_SUBDIR)
    {
	$pfx = $directory . '/';
    }
    $yacc_sources{$pfx . $base . '.' . $ext} = 1;
    $ext =~ tr/y/c/;
    &saw_extension ('c');
    # FIXME: nodist.
    &push_dist_common ($pfx . $base . '.' . $ext);
    return $r;
}

# Rewrite a single yacc++ file.
sub lang_yaccxx_rewrite
{
    my ($directory, $base, $ext) = @_;

    my $r = $LANG_PROCESS;
    my $pfx = '';
    if (defined $options{'subdir-objects'})
    {
	$pfx = $directory . '/';
	$r = $LANG_SUBDIR;
    }
    $yacc_sources{$pfx . $base . '.' . $ext} = 1;
    $ext =~ tr/y/c/;
    &saw_extension ($ext);
    # FIXME: nodist.
    &push_dist_common ($pfx . $base . '.' . $ext);
    return $r;
}

# Rewrite a single lex file.
sub lang_lex_rewrite
{
    my ($directory, $base, $ext) = @_;

    my $r = &lang_c_rewrite ($directory, $base, $ext);
    my $pfx = '';
    if ($r == $LANG_SUBDIR)
    {
	$pfx = $directory . '/';
    }
    $lex_sources{$pfx . $base . '.' . $ext} = 1;
    $ext =~ tr/l/c/;
    &saw_extension ('c');
    # FIXME: nodist.
    &push_dist_common ($pfx . $base . '.' . $ext);
    return $r;
}

# Rewrite a single lex++ file.
sub lang_lexxx_rewrite
{
    my ($directory, $base, $ext) = @_;

    my $r = $LANG_PROCESS;
    my $pfx = '';
    if (defined $options{'subdir-objects'})
    {
	$pfx = $directory . '/';
	$r = $LANG_SUBDIR;
    }
    $lex_sources{$pfx . $base . '.' . $ext} = 1;
    $ext =~ tr/l/c/;
    &saw_extension ($ext);
    # FIXME: nodist.
    &push_dist_common ($pfx . $base . '.' . $ext);
    return $r;
}

# Rewrite a single assembly file.
sub lang_asm_rewrite
{
    return &lang_sub_obj;
}

# Rewrite a single Fortran 77 file.
sub lang_f77_rewrite
{
    return $LANG_PROCESS;
}

# Rewrite a single preprocessed Fortran 77 file.
sub lang_ppf77_rewrite
{
    return $LANG_PROCESS;
}

# Rewrite a single ratfor file.
sub lang_ratfor_rewrite
{
    return $LANG_PROCESS;
}

# Rewrite a single Objective C file.
sub lang_objc_rewrite
{
    return &lang_sub_obj;
}

# Rewrite a single Java file.
sub lang_java_rewrite
{
    return $LANG_SUBDIR;
}

# The lang_X_finish functions are called after all source file
# processing is done.  Each should handle defining rules for the
# language, etc.  A finish function is only called if a source file of
# the appropriate type has been seen.

sub lang_c_finish
{
    # Push all libobjs files onto de_ansi_files.  We actually only
    # push files which exist in the current directory, and which are
    # genuine source files.
    foreach my $file (keys %libsources)
    {
	if ($file =~ /^(.*)\.[cly]$/ && -f "$relative_dir/$file")
	{
	    $de_ansi_files{$1} = 1;
	}
    }

    if (defined $options{'ansi2knr'} && keys %de_ansi_files)
    {
 	# Make all _.c files depend on their corresponding .c files.
 	my @objects;
 	foreach my $base (sort keys %de_ansi_files)
 	{
	    # Each _.c file must depend on ansi2knr; otherwise it
	    # might be used in a parallel build before it is built.
	    # We need to support files in the srcdir and in the build
	    # dir (because these files might be auto-generated.  But
	    # we can't use $< -- some makes only define $< during a
	    # suffix rule.
 	    $output_rules .= ($base . "_.c: $base.c \$(ANSI2KNR)\n\t"
			      . '$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) '
			      . '`if test -f $(srcdir)/' . $base . '.c'
			      . '; then echo $(srcdir)/' . $base . '.c'
			      . '; else echo ' . $base . '.c; fi` '
			      . "| sed 's/^# \\([0-9]\\)/#line \\1/' "
			      . '| $(ANSI2KNR) > ' . $base . "_.c\n");
 	    push (@objects, $base . '_.$(OBJEXT)');
 	    push (@objects, $base . '_.lo')
	      if $seen_libtool;
 	}

 	# Make all _.o (and _.lo) files depend on ansi2knr.
 	# Use a sneaky little hack to make it print nicely.
 	&pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)');
    }

    if (! defined $configure_vars{'CC'})
    {
	# FIXME: line number.
	&am_error ("C source seen but `CC' not defined in `$configure_ac'");
    }
}

sub lang_cxx_finish
{
    my ($ltcompile, $ltlink) = &libtool_compiler;

    &define_variable ('CXXLD', '$(CXX)');
    &define_variable ('CXXLINK', $ltlink . '$(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');

    if (! defined $configure_vars{'CXX'})
    {
	&am_error ("C++ source seen but `CXX' not defined in `$configure_ac'");
    }
}

# This is a helper for both lex and yacc.
sub yacc_lex_finish_helper
{
    return if defined $language_scratch{'lex-yacc-done'};
    $language_scratch{'lex-yacc-done'} = 1;

    # If there is more than one distinct yacc (resp lex) source file
    # in a given directory, then the `ylwrap' program is required to
    # allow parallel builds to work correctly.  FIXME: for now, no
    # line number.
    &require_config_file ($FOREIGN, 'ylwrap');
    if ($config_aux_dir ne '.' && $config_aux_dir ne '')
    {
	&define_variable ('YLWRAP', $config_aux_dir . "/ylwrap");
    }
    else
    {
	&define_variable ('YLWRAP', '$(srcdir)/ylwrap');
    }
}

sub lang_yacc_finish
{
    return if defined $language_scratch{'yacc-done'};
    $language_scratch{'yacc-done'} = 1;

    my %seen_suffix = ();
    my @yacc_files = sort keys %yacc_sources;
    my $yacc_count = scalar (@yacc_files);
    foreach my $file (@yacc_files)
    {
	$file =~ /(\..*)$/;
	&output_yacc_build_rule ($1, $yacc_count > 1)
	    if ! defined $seen_suffix{$1};
	$seen_suffix{$1} = 1;

	$file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
	my $base = $1;
	my $hname = 'h';		# Always use `.h' for header file.
	my $cname = $2;
	$cname =~ tr/y/c/;

	if ((&variable_defined ('AM_YFLAGS')
	     && &variable_value ('AM_YFLAGS') =~ /(^|\s)-d(\s|$)/)
	    || (&variable_defined ('YFLAGS')
		&& &variable_value ('YFLAGS') =~ /(^|\s)-d(\s|$)/)) {
	    # Now generate rule to make the header file.  This should only
	    # be generated if `yacc -d' specified.
	    $output_rules .= "${base}.${hname}: ${base}.${cname}\n";

	    # If the files are built in the build directory, then we want
	    # to remove them with `make clean'.  If they are in srcdir
	    # they shouldn't be touched.  However, we can't determine this
	    # statically, and the GNU rules say that yacc/lex output files
	    # should be removed by maintainer-clean.  So that's what we
	    # do.
	    push (@maintainer_clean_files, "${base}.${hname}");

	    &push_dist_common ("${base}.${hname}");
	}
	push (@maintainer_clean_files, "${base}.${cname}");
    }
    $output_rules .= "\n";

    if (! defined $configure_vars{'YACC'})
    {
	&am_error ("yacc source seen but `YACC' not defined in `$configure_ac'");
    }
    if (&variable_defined ('YACCFLAGS'))
    {
	&am_line_error ('YACCFLAGS',
			"`YACCFLAGS' obsolete; use `YFLAGS' instead");
    }

    if ($yacc_count > 1)
    {
	&yacc_lex_finish_helper;
    }
}


sub lang_lex_finish
{
    return if defined $language_scratch{'lex-done'};
    $language_scratch{'lex-done'} = 1;

    my %seen_suffix = ();
    my $lex_count = scalar (keys %lex_sources);
    foreach my $file (sort keys %lex_sources)
    {
	$file =~ /(\..*)$/;
	&output_lex_build_rule ($1, $lex_count > 1)
	    if (! defined $seen_suffix{$1});
	$seen_suffix{$1} = 1;

	# If the files are built in the build directory, then we want
	# to remove them with `make clean'.  If they are in srcdir
	# they shouldn't be touched.  However, we can't determine this
	# statically, and the GNU rules say that yacc/lex output files
	# should be removed by maintainer-clean.  So that's what we
	# do.
	$file =~ /^(.*)\.(l|ll|l\+\+|lxx|lpp)$/;
	my $cname;
	($cname = $2) =~ tr/l/c/;
	push (@maintainer_clean_files, "${1}.${cname}");
    }

    if (! defined $configure_vars{'LEX'})
    {
	&am_error ("lex source seen but `LEX' not defined in `$configure_ac'");
    }
    if (! $seen_decl_yytext)
    {
	&am_error ("lex source seen but `AC_DECL_YYTEXT' not in `$configure_ac'");
    }

    if ($lex_count > 1)
    {
	&yacc_lex_finish_helper;
    }
}


sub lang_f77_finish
{
    # FIXME: this function can be called more than once.  We should
    # arrange for it to only do anything the first time through.

    my ($ltcompile, $ltlink) = &libtool_compiler;

    &define_variable ('F77LD', '$(F77)');
    &define_variable ('F77LINK',
		      $ltlink . '$(F77LD) $(AM_FFLAGS) $(FFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');

    if (! defined $configure_vars{'F77'})
    {
	&am_error ("Fortran 77 source seen but `F77' not defined in `$configure_ac'");
    }
}

# Preprocessed Fortran 77
#
# The current support for preprocessing Fortran 77 just involves passing
# `$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)' as additional flags
# to the Fortran 77 compiler, since this is how GNU Make does it; see
# the `GNU Make Manual, Edition 0.51 for `make' Version 3.76 Beta'
# (specifically, from info file `(make)Catalogue of Rules').
#
# A better approach would be to write an Autoconf test
# (i.e. AC_PROG_FPP) for a Fortran 77 preprocessor, because not all
# Fortran 77 compilers know how to do preprocessing.  The Autoconf macro
# AC_PROG_FPP should test the Fortran 77 compiler first for
# preprocessing capabilities, and then fall back on cpp (if cpp were
# available).
sub lang_ppf77_finish
{
    &lang_f77_finish;

    # We also handle the case of preprocessing `.F' files into `.f'
    # files.
    $output_rules .= (".F.f:\n"
		      . "\t\$(F77COMPILE) -F \$<\n");
}

sub lang_ratfor_finish
{
    &lang_f77_finish;

    # We also handle the case of preprocessing `.r' files into `.f'
    # files.
    $output_rules .= (".r.f:\n"
		      . "\t\$(RCOMPILE) -F \$<\n");
}

sub lang_objc_finish
{
    my ($ltcompile, $ltlink) = &libtool_compiler;

    &define_variable ('OBJCLD', '$(OBJC)');
    &define_variable ('OBJCLINK', $ltlink . '$(OBJCLD) $(AM_OBJCFLAGS) $(OBJCFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');

    if (! defined $configure_vars{'OBJC'})
    {
	&am_error ("Objective C source seen but `OBJC' not defined in `$configure_ac'");
    }
}

sub lang_java_finish
{
    my ($ltcompile, $ltlink) = &libtool_compiler;

    &define_variable ('GCJLD', '$(GCJ)');
    &define_variable ('GCJLINK',
		      $ltlink . '$(GCJLD) $(AM_GCJFLAGS) $(GCJFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@');

    if (! defined $configure_vars{'GCJ'})
    {
	&am_error ("Java source seen but `GCJ' not defined in `$configure_ac'");
    }
}


# A helper which decides whether libtool is needed.  Returns prefix
# for compiler and linker.
sub libtool_compiler
{
    my ($ltcompile, $ltlink) = ('', '');
    if ($seen_libtool)
    {
	&define_configure_variable ("LIBTOOL");
	$ltcompile = '$(LIBTOOL) --mode=compile ';
	$ltlink = '$(LIBTOOL) --mode=link ';
    }
    return ($ltcompile, $ltlink);
}

# Given a hash table of linker names, pick the name that has the most
# precedence.  This is lame, but something has to have global
# knowledge in order to eliminate the conflict.  Add more linkers as
# required.
sub resolve_linker
{
    my (%linkers) = @_;

    return 'GCJLINK'
	if defined $linkers{'GCJLINK'};
    return 'CXXLINK'
	if defined $linkers{'CXXLINK'};
    return 'F77LINK'
	if defined $linkers{'F77LINK'};
    return 'OBJCLINK'
        if defined $linkers{'OBJCLINK'};
    return 'LINK';
}

# Called to indicate that an extension was used.
sub saw_extension
{
    my ($ext) = @_;
    $extension_seen{$ext} = 1;
}

# Called to ask whether source files have been seen . If HEADERS is 1,
# headers can be included.
sub saw_sources_p
{
    my ($headers) = @_;

    if ($headers)
    {
	$headers = 0;
    }
    else
    {
	$headers = grep ($extension_seen{$_},
			 @{$languages{'header'}->extensions});
    }

    return scalar keys %extension_seen > $headers;
}


# register_language (%ATTRIBUTE)
# ------------------------------
# Register a single language.  LANGUAGE is the name of the language.
# Each %ATTRIBUTE is of the form ATTRIBUTE => VALUE.
sub register_language ($%)
{
    my (%option) = @_;

    # Set the defaults.
    $option{'ansi'} = 0
      unless defined $option{'ansi'};
    $option{'autodep'} = 'no'
      unless defined $option{'autodep'};
    $option{'derived_autodep'} = 'no'
      unless defined $option{'derived_autodep'};
    $option{'linker'} = ''
      unless defined $option{'linker'};

    my $lang = new Language (%option);

    # Fill indexes.
    grep ($extension_map{$_} = $lang->name, @{$lang->extensions});
    $languages{$lang->name} = $lang;
}

# This function is used to find a path from a user-specified suffix to
# `o' or to some other suffix we recognize internally, eg `cc'.
sub derive_suffix
{
    my ($source_ext) = @_;

    # FIXME: hard-coding `o' is a mistake.  Doing something
    # intelligent is harder.
    while ($extension_map{$source_ext} eq ''
	   && $source_ext ne 'o'
	   && defined $suffix_rules{$source_ext})
    {
	$source_ext = $suffix_rules{$source_ext};
    }

    return $source_ext;
}


################################################################

# Pretty-print something.  HEAD is what should be printed at the
# beginning of the first line, FILL is what should be printed at the
# beginning of every subsequent line.
sub pretty_print_internal
{
    my ($head, $fill, @values) = @_;

    my $column = length ($head);
    my $result = $head;

    # Fill length is number of characters.  However, each Tab
    # character counts for eight.  So we count the number of Tabs and
    # multiply by 7.
    my $fill_length = length ($fill);
    $fill_length += 7 * ($fill =~ tr/\t/\t/d);

    foreach (@values)
    {
	# "71" because we also print a space.
	if ($column + length ($_) > 71)
	{
	    $result .= " \\\n" . $fill;
	    $column = $fill_length;
	}
	$result .= ' ' if $result =~ /\S\z/;
	$result .= $_;
	$column += length ($_) + 1;
    }

    $result .= "\n";
    return $result;
}

# Pretty-print something and append to output_vars.
sub pretty_print
{
    $output_vars .= &pretty_print_internal (@_);
}

# Pretty-print something and append to output_rules.
sub pretty_print_rule
{
    $output_rules .= &pretty_print_internal (@_);
}


################################################################


# $STRING
# &conditional_string(@COND-STACK)
# --------------------------------
# Build a string de
sub conditional_string
{
  my (@stack) = @_;

  if (grep (/^FALSE$/, @stack))
    {
      return 'FALSE';
    }
  else
    {
      return join (' ', uniq sort grep (!/^TRUE$/, @stack));
    }
}


# $BOOLEAN
# &conditional_true_when ($COND, $WHEN)
# -------------------------------------
# See if a conditional is true.  Both arguments are conditional
# strings.  This returns true if the first conditional is true when
# the second conditional is true.
# For instance with $COND = `BAR FOO', and $WHEN = `BAR BAZ FOO',
# obviously return 1, and 0 when, for instance, $WHEN = `FOO'.
sub conditional_true_when ($$)
{
    my ($cond, $when) = @_;

    # Make a hash holding all the values from $WHEN.
    my %cond_vals = map { $_ => 1 } split (' ', $when);

    # Check each component of $cond, which looks `COND1 COND2'.
    foreach my $comp (split (' ', $cond))
    {
	# TRUE is always true.
	return 1 if $comp eq 'TRUE';
	return 0 if ! defined $cond_vals{$comp};
    }

    return 1;
}


# $BOOLEAN
# &conditionals_true_when (@CONDS, @WHENS)
# ----------------------------------------
# Same as above, but true if all the @CONDS are true when *ALL*
# the @WHENS are sufficient.
#
# If there are no @CONDS, then return true, of course. *BUT*, even if there
# are @CONDS but @WHENS is empty, return true.  This is counter intuitive,
# and against all the rules of logic, but is needed by the current code.
# FIXME: Do something saner when the logic of conditionals is understood.
sub conditionals_true_when (@@)
{
    my (@conds, @whens) = @_;

    foreach my $cond (@conds)
    {
      foreach my $when (@whens)
      {
	return 0
	  unless conditional_true_when ($cond, $when);
      }
    }

    return 1;
}


# $NEGATION
# condition_negate ($COND)
# ------------------------
sub condition_negate ($)
{
    my ($cond) = @_;

    $cond =~ s/TRUE$/TRUEO/;
    $cond =~ s/FALSE$/TRUE/;
    $cond =~ s/TRUEO$/FALSE/;

    return $cond;
}


# Compare condition names.
# Issue them in alphabetical order, foo_TRUE before foo_FALSE.
sub by_condition
{
    # Be careful we might be comparing `' or `#'.
    $a =~ /^(.*)_(TRUE|FALSE)$/;
    my ($aname, $abool) = ($1 || '', $2 || '');
    $b =~ /^(.*)_(TRUE|FALSE)$/;
    my ($bname, $bbool) = ($1 || '', $2 || '');
    return ($aname cmp $bname
	    # Don't bother with IFs, given that TRUE is after FALSE
	    # just cmp in the reverse order.
	    || $bbool cmp $abool
	    # Just in case...
	    || $a cmp $b);
}


# &make_condition (@CONDITIONS)
# -----------------------------
# Transform a list of conditions (themselves can be an internal list
# of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
# Make conditional (a pattern for AC_SUBST).
# Correctly returns the empty string when there are no conditions.
sub make_condition
{
    my $res = conditional_string (@_);

    # There are no conditions.
    if ($res eq '')
      {
	# Nothing to do.
      }
    # It's impossible.
    elsif ($res eq 'FALSE')
      {
	$res = '#';
      }
    # Build it.
    else
      {
	$res = '@' . $res . '@';
	$res =~ s/ /@@/g;
      }

    return $res;
}



## ------------------------------ ##
## Handling the condition stack.  ##
## ------------------------------ ##


# $COND_STRING
# cond_stack_if ($NEGATE, $COND, $WHERE)
# --------------------------------------
sub cond_stack_if ($$$)
{
  my ($negate, $cond, $where) = @_;

  &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
    if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;

  $cond = "${cond}_TRUE"
    unless $cond =~ /^TRUE|FALSE$/;
  $cond = condition_negate ($cond)
    if $negate;

  push (@cond_stack, $cond);

  return conditional_string (@cond_stack);
}


# $COND_STRING
# cond_stack_else ($NEGATE, $COND, $WHERE)
# ----------------------------------------
sub cond_stack_else ($$$)
{
  my ($negate, $cond, $where) = @_;

  if (! @cond_stack)
    {
      &am_file_error ($where, "else without if");
      return;
    }

  $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);

  # If $COND is given, check against it.
  if (defined $cond)
    {
      $cond = "${cond}_TRUE"
	unless $cond =~ /^TRUE|FALSE$/;
      $cond = condition_negate ($cond)
	if $negate;

      &am_file_error ($where,
		      "else reminder ($negate$cond) incompatible with "
		      . "current conditional: $cond_stack[$#cond_stack]")
	if $cond_stack[$#cond_stack] ne $cond;
    }

  return conditional_string (@cond_stack);
}


# $COND_STRING
# cond_stack_endif ($NEGATE, $COND, $WHERE)
# -----------------------------------------
sub cond_stack_endif ($$$)
{
  my ($negate, $cond, $where) = @_;
  my $old_cond;

  if (! @cond_stack)
    {
      &am_file_error ($where, "endif without if");
      return;
    }


  # If $COND is given, check against it.
  if (defined $cond)
    {
      $cond = "${cond}_TRUE"
	unless $cond =~ /^TRUE|FALSE$/;
      $cond = condition_negate ($cond)
	if $negate;

      &am_file_error ($where,
		      "endif reminder ($negate$cond) incompatible with "
		      . "current conditional: $cond_stack[$#cond_stack]")
	if $cond_stack[$#cond_stack] ne $cond;
    }

  pop @cond_stack;

  return conditional_string (@cond_stack);
}





## ------------------------ ##
## Handling the variables.  ##
## ------------------------ ##


# check_ambiguous_conditional ($VAR, $COND)
# -----------------------------------------
# Check for an ambiguous conditional.  This is called when a variable
# is being defined conditionally.  If we already know about a
# definition that is true under the same conditions, then we have an
# ambiguity.
sub check_ambiguous_conditional ($$)
{
    my ($var, $cond) = @_;
    foreach my $vcond (keys %{$var_value{$var}})
    {
       my $message;
       if ($vcond eq $cond)
       {
	   $message = "$var multiply defined in condition $cond";
       }
       elsif (&conditional_true_when ($vcond, $cond))
       {
	 $message = ("$var was already defined in condition $vcond, "
		     . "which implies condition $cond");
       }
       elsif (&conditional_true_when ($cond, $vcond))
       {
	   $message = ("$var was already defined in condition $vcond, "
		       . "which is implied by condition $cond");
       }
       if ($message)
       {
	   &am_line_error ($var, $message);
	   macro_dump ($var);
       }
   }
}


# &macro_define($VAR, $VAR_IS_AM, $TYPE, $COND, $VALUE, $WHERE)
# -------------------------------------------------------------
# The $VAR can go from Automake to user, but not the converse.
sub macro_define ($$$$$$)
{
  my ($var, $var_is_am, $type, $cond, $value, $where) = @_;

  $cond ||= 'TRUE';

  # An Automake variable must be consistently defined with the same
  # sign by Automake.  A user variable must be set by either `=' or
  # `:=', and later promoted to `+='.
  if ($var_is_am)
    {
      if (defined $var_type{$var} && $var_type{$var} ne $type)
	{
	  am_line_error ($var,
			 ("$var was set with `$var_type{$var}=' "
			  . "and is now set with `$type='"));
	}
    }
  else
    {
      if (!defined $var_type{$var} && $type eq '+')
	{
	  am_line_error ($var, "$var must be set with `=' before using `+='");
	}
    }
  $var_type{$var} = $type;

  # Differentiate the first assignment (including with `+=').
  if ($type eq '+' && defined $var_value{$var}{$cond})
    {
      if (substr ($var_value{$var}{$cond}, -1) eq "\n")
	{
	  # Insert a backslash before a trailing newline.
	  $var_value{$var}{$cond} =
	    substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
	}
      elsif ($var_value{$var}{$cond})
	{
	  # Insert a separator.
	  $var_value{$var}{$cond} .= ' ';
	}
       $var_value{$var}{$cond} .= $value;
    }
  else
    {
      # The first assignment to a macro sets the line number.  Ideally I
      # suppose we would associate line numbers with random bits of text.
      # FIXME: We sometimes redefine some variables, but we want to keep
      # the original location.  More subs are needed to handle
      # properly variables.  Once this done, remove this hack.
      $var_line{$var} = $where
	unless defined $var_line{$var};

      # If Automake tries to override a value specified by the user,
      # just don't let it do.
      if (defined $var_value{$var}{$cond} && !$var_is_am{$var} && $var_is_am)
	{
	  if ($verbose)
	    {
	      print STDERR "$me: refusing to override the user definition of:\n";
	      variable_dump ($var);
	      print STDERR "$me: with `$cond' => `$value'\n";
	    }
	}
      else
	{
	  # There must be no previous value unless the user is redefining
	  # an Automake variable or an AC_SUBST variable.
	  check_ambiguous_conditional ($var, $cond)
	    unless ($var_is_am{$var} && !$var_is_am
		    || exists $configure_vars{$var});

	  $var_value{$var}{$cond} = $value;
	}
    }

  # An Automake variable can be given to the user, but not the converse.
  if (! defined $var_is_am{$var} || !$var_is_am)
    {
      $var_is_am{$var} = $var_is_am;
    }
}


# &variable_delete ($VAR, [@CONDS])
# ---------------------------------
# Forget about $VAR under the conditions @CONDS, or completely if
# @CONDS is empty.
sub variable_delete ($@)
{
  my ($var, @conds) = @_;

  if (!@conds)
    {
      delete $var_value{$var};
      delete $var_line{$var};
      delete $var_is_am{$var};
      delete $var_comment{$var};
      delete $var_type{$var};
    }
  else
    {
      foreach my $cond (@conds)
	{
	  delete $var_value{$var}{$cond};
	}
    }
}


# &macro_dump ($VAR)
# ------------------
sub macro_dump ($)
{
  my ($var) = @_;

  if (!exists $var_value{$var})
    {
      print STDERR "  $var does not exist\n";
    }
  else
    {
      my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
      my $where = (defined $var_line{$var}
		   ? $var_line{$var} : "undefined");
      print STDERR "$var_comment{$var}"
	if defined $var_comment{$var};
      print STDERR "  $var ($var_is_am, where = $where) $var_type{$var}=\n";
      print STDERR "  {\n";
      foreach my $vcond (sort by_condition keys %{$var_value{$var}})
	{
	  print STDERR "    $vcond => $var_value{$var}{$vcond}\n";
	}
      print STDERR "  }\n";
    }
}


# &macros_dump ()
# ---------------
sub macros_dump ()
{
  my ($var) = @_;

  print STDERR "%var_value =\n";
  print STDERR "{\n";
  foreach my $var (sort (keys %var_value))
    {
      macro_dump ($var);
    }
  print STDERR "}\n";
}


# $BOOLEAN
# &variable_defined ($VAR, [$COND])
# ---------------------------------
# See if a variable exists.  $VAR is the variable name, and $COND is
# the condition which we should check.  If no condition is given, we
# currently return true if the variable is defined under any
# condition.
sub variable_defined ($$)
{
    my ($var, $cond) = @_;

    # Unfortunately we can't just check for $var_value{VAR}{COND}
    # as this would make perl create $condition{VAR}, which we
    # don't want.
    if (!exists $var_value{$var})
      {
	if (defined $targets{$var})
	  {
	    &am_line_error ($var, "`$var' is a target; expected a variable")
	  }
	# The variable is not defined
	return 0;
      }

    if ($cond && !exists $var_value{$var}{$cond})
      {
	# The variable is not defined for the given condition.
	return 0;
      }

    # Even a var_value examination is good enough for us.  FIXME:
    # really should maintain examined status on a per-condition basis.
    $content_seen{$var} = 1;
    return 1;
}

# Mark a variable as examined.
sub examine_variable
{
    my ($var) = @_;
    &variable_defined ($var);
}

# Return the set of conditions for which a variable is defined.

# If the variable is not defined conditionally, and is not defined in
# terms of any variables which are defined conditionally, then this
# returns the empty list.

# If the variable is defined conditionally, but is not defined in
# terms of any variables which are defined conditionally, then this
# returns the list of conditions for which the variable is defined.

# If the variable is defined in terms of any variables which are
# defined conditionally, then this returns a full set of permutations
# of the subvariable conditions.  For example, if the variable is
# defined in terms of a variable which is defined for COND_TRUE,
# then this returns both COND_TRUE and COND_FALSE.  This is
# because we will need to define the variable under both conditions.

sub variable_conditions ($)
{
    my ($var) = @_;
    my %uniqify;
    my @uniq_list;

    %vars_scanned = ();
    foreach my $cond (&variable_conditions_sub ($var, '', ()))
    {
        next
	  if $cond eq 'FALSE';
	$uniqify{$cond} = 1;
    }

    @uniq_list = sort by_condition keys %uniqify;
    # Note we cannot just do `return sort keys %uniqify', because this
    # function is sometimes used in a scalar context.
    return @uniq_list;
}


# $BOOLEAN
# &variable_conditionally_defined ($VAR)
# --------------------------------------
sub variable_conditionally_defined ($)
{
    my ($var) = @_;
    foreach my $cond (variable_conditions ($var))
      {
	return 1
	  unless $cond =~ /^TRUE|FALSE$/;
      }
    return 0;
}



# &variable_conditions_sub ($VAR, $PARENT, @PARENT_CONDS)
# -------------------------------------------------------
# A subroutine of variable_conditions.  We only return conditions
# which are true for all the conditions in @PARENT_CONDS.
sub variable_conditions_sub
{
    my ($var, $parent, @parent_conds) = @_;
    my @new_conds = ();

    if (defined $vars_scanned{$var})
    {
	&am_line_error ($parent, "variable `$var' recursively defined");
	return ();
    }
    $vars_scanned{$var} = 1;

    my @this_conds = ();
    foreach my $vcond (keys %{$var_value{$var}})
    {
	next
	  if ! conditionals_true_when ((@parent_conds), ($vcond));

	push (@this_conds, $vcond);

	push (@parent_conds, $vcond);
	my @subvar_conds = ();
	foreach (split (' ', $var_value{$var}{$vcond}))
	{
	    # If a comment seen, just leave.
	    last if /^#/;

	    # Handle variable substitutions.
	    if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
	    {
		push (@subvar_conds,
		      &variable_conditions_sub ($1, $var, @parent_conds));
	    }
	}
	pop (@parent_conds);

	# If there are no conditional subvariables, then we want to
	# return this condition.  Otherwise, we want to return the
	# permutations of the subvariables.
	if (! @subvar_conds)
	{
	    push (@new_conds, $vcond);
	}
	else
	{
	    push (@new_conds, &variable_conditions_reduce (@subvar_conds));
	}
    }

    # Unset our entry in vars_scanned.  We only care about recursive
    # definitions.
    delete $vars_scanned{$var};

    # If there are no parents, then this call is the top level call.
    if (! $parent)
      {
	# Now we want to return all permutations of the subvariable
	# conditions.
	my %allconds = ();
	foreach my $item (@new_conds)
	{
	    foreach (split (' ', $item))
	    {
		s/^(.*)_(TRUE|FALSE)$/$1_TRUE/;
		$allconds{$_} = 1;
	    }
	}
	return &variable_conditions_permutations (sort keys %allconds);
      }

    # If we are being called on behalf of another variable, we need to
    # return all possible permutations of the conditions.  We have
    # already handled everything in @this_conds along with their
    # subvariables.  We now need to add any permutations that are not
    # in @this_conds.
    foreach my $this_cond (@this_conds)
    {
	my @perms =
	    &variable_conditions_permutations (split(' ', $this_cond));
	foreach my $perm (@perms)
	{
	    my $ok = 1;
	    foreach my $scan (@this_conds)
	    {
		if (&conditional_true_when ($perm, $scan)
		    || &conditional_true_when ($scan, $perm))
		{
		    $ok = 0;
		    last;
		}
	    }
	    next if ! $ok;

	    next
	      if ! conditionals_true_when ((@parent_conds), ($perm));

	    # This permutation was not already handled, and is valid
	    # for the parents.
	    push (@new_conds, $perm);
	}
    }

    return @new_conds;
}


# Filter a list of conditionals so that only the exclusive ones are
# retained.  For example, if both `COND1_TRUE COND2_TRUE' and
# `COND1_TRUE' are in the list, discard the latter.
sub variable_conditions_reduce
{
    my (@conds) = @_;
    my @ret = ();
    foreach my $cond (@conds)
    {
        # FALSE is absorbent.
        if ($cond eq 'FALSE')
	  {
	    return ('FALSE');
	  }
	elsif (conditionals_true_when (($cond), (@ret)))
	  {
	    push (@ret, $cond);
	  }
    }

    return @ret;
}

# Return a list of permutations of a conditional string.
sub variable_conditions_permutations
{
    my (@comps) = @_;
    return ()
	if ! @comps;
    my $comp = shift (@comps);
    return &variable_conditions_permutations (@comps)
	if $comp eq '';
    my $neg = condition_negate ($comp);

    my @ret;
    foreach my $sub (&variable_conditions_permutations (@comps))
    {
	push (@ret, "$comp $sub");
	push (@ret, "$neg $sub");
    }
    if (! @ret)
    {
	push (@ret, $comp);
	push (@ret, $neg);
    }
    return @ret;
}


# $BOOL
# &check_variable_defined_unconditionally($VAR, $PARENT)
# ------------------------------------------------------
# Warn if a variable is conditionally defined.  This is called if we
# are using the value of a variable.
sub check_variable_defined_unconditionally ($$)
{
    my ($var, $parent) = @_;
    foreach my $cond (keys %{$var_value{$var}})
    {
        next
	  if $cond =~ /^TRUE|FALSE$/;

	if ($parent)
	{
	    &am_line_error ($parent,
			    "warning: automake does not support conditional definition of $var in $parent");
	}
	else
	{
	    &am_line_error ($parent,
			    "warning: automake does not support $var being defined conditionally");
	    macro_dump ($var);

	}
    }
}


# Get the TRUE value of a variable, warn if the variable is
# conditionally defined.
sub variable_value
{
    my ($var) = @_;
    &check_variable_defined_unconditionally ($var);
    return $var_value{$var}{'TRUE'};
}


# @VALUES
# &value_to_list ($VAR, $VAL, $COND)
# ----------------------------------
# Convert a variable value to a list, split as whitespace.  This will
# recursively follow $(...) and ${...} inclusions.  It preserves @...@
# substitutions.
#
# If COND is 'all', then all values under all conditions should be
# returned; if COND is a particular condition (all conditions are
# surrounded by @...@) then only the value for that condition should
# be returned; otherwise, warn if VAR is conditionally defined.
# SCANNED is a global hash listing whose keys are all the variables
# already scanned; it is an error to rescan a variable.
sub value_to_list
{
    my ($var, $val, $cond) = @_;
    my @result;

    # Strip backslashes
    $val =~ s/\\(\n|$)/ /g;

    foreach (split (' ', $val))
    {
	# If a comment seen, just leave.
	last if /^#/;

	# Handle variable substitutions.
	if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/)
	{
	    my $varname = $1;

	    # If the user uses a losing variable name, just ignore it.
	    # This isn't ideal, but people have requested it.
	    next if ($varname =~ /\@.*\@/);

	    my ($from, $to);
	    my @temp_list;
	    if ($varname =~ /^([^:]*):([^=]*)=(.*)$/)
	    {
		$varname = $1;
		$to = $3;
		($from = $2) =~ s/(\W)/\\$1/g;
	    }

	    # Find the value.
	    @temp_list = &variable_value_as_list_worker ($1, $cond, $var);

	    # Now rewrite the value if appropriate.
	    if ($from)
	    {
		grep (s/$from$/$to/, @temp_list);
	    }

	    push (@result, @temp_list);
	}
	else
	{
	    push (@result, $_);
	}
    }

    return @result;
}

# Return contents of variable as list, split as whitespace.  This will
# recursively follow $(...) and ${...} inclusions.  It preserves @...@
# substitutions.  If COND is 'all', then all values under all
# conditions should be returned; if COND is a particular condition
# (all conditions are surrounded by @...@) then only the value for
# that condition should be returned; otherwise, warn if VAR is
# conditionally defined.  If PARENT is specified, it is the name of
# the including variable; this is only used for error reports.
sub variable_value_as_list_worker
{
    my ($var, $cond, $parent) = @_;
    my @result = ();

    if (! defined $var_value{$var})
    {
        if (defined $targets{$var})
	  {
	    &am_line_error ($var, "`$var' is a target; expected a variable");
	  }
	else
	  {
	    &am_line_error ($parent, "variable `$var' not defined");
	  }
    }
    elsif (defined $vars_scanned{$var})
    {
	# `vars_scanned' is a global we use to keep track of which
	# variables we've already examined.
	&am_line_error ($parent, "variable `$var' recursively defined");
    }
    elsif ($cond eq 'all')
    {
	$vars_scanned{$var} = 1;
	foreach my $vcond (keys %{$var_value{$var}})
	{
	    my $val = $var_value{$var}{$vcond};
	    push (@result, &value_to_list ($var, $val, $cond));
	}
    }
    else
    {
        $cond ||= 'TRUE';
	$vars_scanned{$var} = 1;
	my $onceflag;
	foreach my $vcond (keys %{$var_value{$var}})
	{
	    my $val = $var_value{$var}{$vcond};
	    if (&conditional_true_when ($vcond, $cond))
	    {
		# Warn if we have an ambiguity.  It's hard to know how
		# to handle this case correctly.
		&check_variable_defined_unconditionally ($var, $parent)
		    if $onceflag;
		$onceflag = 1;
		push (@result, &value_to_list ($var, $val, $cond));
	    }
	}
    }

    # Unset our entry in vars_scanned.  We only care about recursive
    # definitions.
    delete $vars_scanned{$var};

    return @result;
}


# &variable_output ($VAR, [@CONDS])
# ---------------------------------
# Output all the values of $VAR is @COND is not specified, else only
# that corresponding to @COND.
sub variable_output ($@)
{
  my ($var, @conds) = @_;

  @conds = sort by_condition keys %{$var_value{$var}}
    unless @conds;

  $output_vars .= $var_comment{$var}
    if defined $var_comment{$var};

  foreach my $cond (@conds)
    {
      my $val = $var_value{$var}{$cond};
      my $equals = $var_type{$var} eq ':' ? ':=' : '=';
      my $output_var = "$var $equals $val";
      $output_var =~ s/^/&make_condition ($cond)/meg;
      $output_vars .= $output_var . "\n";
    }
}


# &variable_pretty_output ($VAR, [@CONDS])
# ----------------------------------------
# Likewise, but pretty, i.e., we *split* the values at spaces.   Use only
# with variables holding filenames.
sub variable_pretty_output ($@)
{
  my ($var, @conds) = @_;

  @conds = sort by_condition keys %{$var_value{$var}}
    unless @conds;

  $output_vars .= $var_comment{$var}
    if defined $var_comment{$var};

  foreach my $cond (@conds)
    {
      my $val = $var_value{$var}{$cond};
      my $equals = $var_type{$var} eq ':' ? ':=' : '=';
      my $make_condition = make_condition ($cond);
      $output_vars .= pretty_print_internal ("$make_condition$var $equals",
					     "$make_condition\t",
					     split (' ' , $val));
    }
}


# This is just a wrapper for variable_value_as_list_worker that
# initializes the global hash `vars_scanned'.  This hash is used to
# avoid infinite recursion.
sub variable_value_as_list
{
    my ($var, $cond, $parent) = @_;
    %vars_scanned = ();
    return &variable_value_as_list_worker ($var, $cond, $parent);
}


# Like define_variable, but the value is a list, and the variable may
# be defined conditionally.  The second argument is the conditional
# under which the value should be defined; this should be the empty
# string to define the variable unconditionally.  The third argument
# is a list holding the values to use for the variable.  The value is
# pretty printed in the output file.
sub define_pretty_variable
{
    my ($var, $cond, @value) = @_;

    # Beware that an empty $cond has a different semantics for
    # macro_define and variable_pretty_output.
    $cond ||= 'TRUE';

    if (! &variable_defined ($var, $cond))
    {
        macro_define ($var, 1, '', $cond, join (' ', @value), undef);
	variable_pretty_output ($var, $cond || 'TRUE');
	$content_seen{$var} = 1;
    }
}


# define_variable ($VAR, $VALUE)
# ------------------------------
# Define a new user variable VAR to VALUE, but only if not already defined.
sub define_variable
{
    my ($var, $value) = @_;

    define_pretty_variable ($var, 'TRUE', $value);
}


# Like define_variable, but define a variable to be the configure
# substitution by the same name.
sub define_configure_variable
{
    my ($var) = @_;
    my $value = '@' . $var . '@';
    &define_variable ($var, $value);
}

# Define a compiler variable.  We also handle defining the `LT'
# version of the command when using libtool.
sub define_compiler_variable
{
    my ($var, $ltcompile, $value) = @_;
    my $name = $var;
    &define_variable ($name, $value);
    &define_variable ('LT' . $name, $ltcompile . $value)
	if $seen_libtool;
}

################################################################

## ---------------- ##
## Handling rules.  ##
## ---------------- ##

sub rule_define ($$$$)
{
  my ($target, $rule_is_am, $cond, $where) = @_;

  if (defined $targets{$target}
      && ($cond
	  ? ! defined $target_conditional{$target}
	  : defined $target_conditional{$target}))
    {
      &am_line_error ($target,
		      "$target defined both conditionally and unconditionally");
    }

  # Value here doesn't matter; for targets we only note existence.
  $targets{$target} = $where;
  if ($cond)
    {
      if ($target_conditional{$target})
	{
	  &check_ambiguous_conditional ($target, $cond);
	}
      $target_conditional{$target}{$cond} = $where;
    }


  # Check the rule for being a suffix rule. If so, store in a hash.

  if ((my ($source_suffix, $object_suffix)) = ($1 =~ $SUFFIX_RULE_PATTERN))
  {
    $suffix_rules{$source_suffix} = $object_suffix;
    print "Sources ending in .$source_suffix become .$object_suffix\n"
      if $verbose;
    # Set SUFFIXES from suffix_rules.
    push @suffixes, ".$source_suffix", ".$object_suffix";
  }
}


# See if a target exists.
sub target_defined
{
    my ($target) = @_;
    return defined $targets{$target};
}


################################################################

# Read Makefile.am and set up %contents.  Simultaneously copy lines
# from Makefile.am into $output_trailer or $output_vars as
# appropriate.  NOTE we put rules in the trailer section.  We want
# user rules to come after our generated stuff.
sub read_am_file
{
    my ($amfile) = @_;

    my $am_file = new IO::File ("< $amfile");
    if (! $am_file)
    {
	die "$me: couldn't open `$amfile': $!\n";
    }
    print "$me: reading $amfile\n" if $verbose;

    my $spacing = '';
    my $comment = '';
    my $blank = 0;

    while ($_ = $am_file->getline)
    {
	if (/$IGNORE_PATTERN/o)
	{
	    # Merely delete comments beginning with two hashes.
	}
	elsif (/$WHITE_PATTERN/o)
	{
	    # Stick a single white line before the incoming macro or rule.
	    $spacing = "\n";
	    $blank = 1;
	}
	elsif (/$COMMENT_PATTERN/o)
	{
	    # Stick comments before the incoming macro or rule.  Make
	    # sure a blank line preceeds first block of comments.
	    $spacing = "\n" unless $blank;
	    $blank = 1;
	    $comment .= $spacing . $_;
	    $spacing = '';
	}
	else
	{
	    last;
	}
    }

    $output_vars .= $comment . "\n";
    $comment = '';
    $spacing = "\n";

    # We save the conditional stack on entry, and then check to make
    # sure it is the same on exit.  This lets us conditonally include
    # other files.
    my @saved_cond_stack = @cond_stack;
    my $cond = conditional_string (@cond_stack);

    my $saw_bk = 0;
    my $was_rule = 0;
    my $is_ok_macro;
    my $last_var_name = '';
    my $last_var_type = '';
    my $last_var_value = '';
    while ($_)
    {
	$_ .= "\n"
	    unless substr ($_, -1, 1) eq "\n";

	# Don't look at MAINTAINER_MODE_TRUE here.  That shouldn't be
	# used by users.  @MAINT@ is an anachronism now.
	$_ =~ s/\@MAINT\@//g
	    unless $seen_maint_mode;

	if (/$IGNORE_PATTERN/o)
	{
	    # Merely delete comments beginning with two hashes.
	}
	elsif (/$WHITE_PATTERN/o)
	{
	    # Stick a single white line before the incoming macro or rule.
	    $spacing = "\n";
	    &am_line_error ($., "blank line following trailing backslash")
		if $saw_bk;
	}
	elsif (/$COMMENT_PATTERN/o)
	{
	    # Stick comments before the incoming macro or rule.
	    $comment .= $spacing . $_;
	    $spacing = '';
	    &am_line_error ($., "comment following trailing backslash")
		if $saw_bk;
	}
	elsif ($saw_bk)
	{
	    if ($was_rule)
	    {
	        $output_trailer .= &make_condition (@cond_stack);
		$output_trailer .= $_;
	    }
	    else
	    {
	      $last_var_value .= ' '
		unless $last_var_value =~ /\s$/;
	      $last_var_value .= $_;

	      if (!/\\$/)
		{
		  $var_comment{$last_var_name} .= "$spacing"
		    if (!defined $var_comment{$last_var_name}
			|| substr ($var_comment{$last_var_name}, -1) ne "\n");
		  $var_comment{$last_var_name} .= "$comment";
		  $comment = $spacing = '';
		  macro_define ($last_var_name, 0,
				$last_var_type, $cond,
				$last_var_value, $.)
		    if $cond ne 'FALSE';
		  push (@var_list, $last_var_name);
		}
	    }
	}

	elsif (/$IF_PATTERN/o)
	  {
	    $cond = cond_stack_if ($1, $2, "$amfile:$.");
	  }
	elsif (/$ELSE_PATTERN/o)
	  {
	    $cond = cond_stack_else ($1, $2, "$amfile:$.");
	  }
	elsif (/$ENDIF_PATTERN/o)
	  {
	    $cond = cond_stack_endif ($1, $2, "$amfile:$.");
	  }

	elsif (/$RULE_PATTERN/o)
	{
	    # Found a rule.
	    $was_rule = 1;

	    rule_define ($1, 0, $cond, $.);

	    $var_line{$1} = $.;
	    $output_trailer .= $comment . $spacing;
            $output_trailer .= &make_condition (@cond_stack);
            $output_trailer .= $_;
	    $comment = $spacing = '';
	}
	elsif (($is_ok_macro = /$MACRO_PATTERN/o)
	       || /$BOGUS_MACRO_PATTERN/o)
	{
	    # Error if bogus.
	    &am_line_error ($., "bad macro name `$last_var_name'")
		if ! $is_ok_macro;

	    # Found a macro definition.
	    $was_rule = 0;
	    $last_var_name = $1;
	    $last_var_type = $2;
	    $last_var_value = $3;
	    if ($3 ne '' && substr ($3, -1) eq "\\")
	    {
		# We preserve the `\' because otherwise the long lines
		# that are generated will be truncated by broken
		# `sed's.
		$last_var_value = $3 . "\n";
	    }

	    if (!/\\$/)
	      {
		# FIXME: this doesn't always work correctly; it will
		# group all comments for a given variable, no matter
		# where defined.
		# Accumulating variables must not be output.
		$var_comment{$last_var_name} .= "$spacing"
		  if (!defined $var_comment{$last_var_name}
		      || substr ($var_comment{$last_var_name}, -1) ne "\n");
		$var_comment{$last_var_name} .= "$comment";
		$comment = $spacing = '';

		macro_define ($last_var_name, 0,
			      $last_var_type, $cond,
			      $last_var_value, $.)
		  if $cond ne 'FALSE';
		push (@var_list, $last_var_name);
	      }
	}
        elsif (/$INCLUDE_PATTERN/o)
        {
            my $path = $1;

            if ($path =~ s/^\$\(top_srcdir\)\///)
            {
                push (@include_stack, "\$\(top_srcdir\)/$path");
            }
            else
            {
                $path =~ s/\$\(srcdir\)\///;
                push (@include_stack, "\$\(srcdir\)/$path");
                $path = $relative_dir . "/" . $path;
            }
            &read_am_file ($path);
        }
	else
        {
	    # This isn't an error; it is probably a continued rule.
	    # In fact, this is what we assume.
	    $was_rule = 1;
	    $output_trailer .= $comment . $spacing;
	    $output_trailer .= &make_condition  (@cond_stack);
	    $output_trailer .= $_;
	    $comment = $spacing = '';
	}

	$saw_bk = /\\$/;
        $_ = $am_file->getline;
    }

    $output_trailer .= $comment;

    if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
    {
	if (@cond_stack)
	{
	    &am_error ("unterminated conditionals: @cond_stack");
	}
	else
	{
	    # FIXME: better error message here.
	    &am_error ("conditionals not nested in include file");
	}
    }
}


# define_standard_variables ()
# ----------------------------
# A helper for read_main_am_file which initializes configure variables
# and variables from header-vars.am.  This is a subr so we can call it
# twice.
sub define_standard_variables
{
    my $saved_output_vars = $output_vars;
    my ($comments, $variables, $rules) =
      &file_contents_internal ('header-vars',
		     ('BUILD'    => $seen_canonical == $AC_CANONICAL_SYSTEM,
		      'HOST'     => $seen_canonical,
		      'TARGET'   => $seen_canonical == $AC_CANONICAL_SYSTEM,
		      'top_builddir' => backname ($relative_dir)));

    # This will output the definitions in $output_vars, which we don't
    # want...
    foreach my $var (sort keys %configure_vars)
    {
        &define_configure_variable ($var);
        push (@var_list, $var);
    }

    # ... hence, we restore $output_vars.
    $output_vars = $saved_output_vars . $comments . $rules;
}

# Read main am file.
sub read_main_am_file
{
    my ($amfile) = @_;

    # This supports the strange variable tricks we are about to play.
    if (scalar keys %var_value > 0)
      {
	macros_dump ();
	&prog_error ("variable defined before read_main_am_file");
      }

    # Generate copyright header for generated Makefile.in.
    # We do discard the output of predefined variables, handled below.
    $output_vars = ("# $in_file_name generated automatically by automake "
		   . $VERSION . " from $am_file_name.\n");
    $output_vars .= $gen_copyright;

    # We want to predefine as many variables as possible.  This lets
    # the user set them with `+=' in Makefile.am.  However, we don't
    # want these initial definitions to end up in the output quite
    # yet.  So we just load them, but output them later.
    &define_standard_variables;

    # Read user file, which might override some of our values.
    &read_am_file ($amfile);

    # Ouput all the Automake variables.  If the user changed one, then
    # it is now marked as owned by the user.
    foreach my $var (uniq @var_list)
    {
	# Don't process user variables.
        variable_output ($var)
	  unless !$var_is_am{$var};
    }

    # Now dump the user variables that were defined.  We do it in the same
    # order in which they were defined (skipping duplicates).
    foreach my $var (uniq @var_list)
    {
	# Don't process Automake variables.
        variable_output ($var)
	  unless $var_is_am{$var};
    }
}

################################################################

# $FLATTENED
# &flatten ($STRING)
# ------------------
# Flatten the $STRING and return the result.
sub flatten
{
  $_ = shift;

  s/\\\n//somg;
  s/\s+/ /g;
  s/^ //;
  s/ $//;

  return $_;
}


# @PARAGRAPHS
# &make_paragraphs ($MAKEFILE, [%TRANSFORM])
# ------------------------------------------
# Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
# paragraphs.
sub make_paragraphs ($%)
{
    my ($file, %transform) = @_;

    # Complete %transform with global options and make it a Perl
    # $command.
    my $command =
      # We don't use IGNORE_PATTERN because it contains $ which
      # prevents us from matching the end of line.
      "s/##([^#\n].*)?\\n//gmo;"
	. &transform (%transform,

		      'CYGNUS'          => $cygnus_mode,
		      'MAINTAINER-MODE'
		      => $seen_maint_mode ? '@MAINTAINER_MODE_TRUE@' : '',

		      'SHAR'        => $options{'dist-shar'} || 0,
		      'BZIP2'       => $options{'dist-bzip2'} || 0,
		      'ZIP'         => $options{'dist-zip'} || 0,
		      'COMPRESS'    => $options{'dist-tarZ'} || 0,

		      'INSTALL-INFO' => !$options{'no-installinfo'},
		      'INSTALL-MAN'  => !$options{'no-installman'},
		      'CK-NEWS'      => $options{'check-news'} || 0,

		      'SUBDIRS'      => &variable_defined ('SUBDIRS'),
		      'TOPDIR'       => backname ($relative_dir),
		      'TOPDIR_P'     => $relative_dir eq '.',
		      'CONFIGURE-AC' => $configure_ac,

		      'LIBTOOL'      => defined $configure_vars{'LIBTOOL'})
	  # We don't need more than two consecutive new-lines.
	  . 's/\n{3,}/\n\n/g';

    # Swallow the file and apply the COMMAND.
    my $fc_file = new IO::File ("< $file");
    if (! $fc_file)
    {
	die "$me: installation error: cannot open `$file'\n";
    }
    # Looks stupid?
    print "$me: reading $file\n"
      if $verbose;
    my $saved_dollar_slash = $/;
    undef $/;
    $_ = $fc_file->getline;
    $/ = $saved_dollar_slash;
    eval $command;
    $fc_file->close;
    my $content = $_;

    # A rule has three parts: a list of targets, a list of dependencies,
    # and optionally actions.
    my $RULE_PATTERN =
      "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";


    # Split at unescaped new lines.
    my @lines = split (/(?<!\\)\n/, $content);
    my @res;

    while (defined ($_ = shift @lines))
      {
	my $paragraph = "$_";
	# If we are a rule, eat as long as we start with a tab.
	if (/$RULE_PATTERN/smo)
	  {
	    while (defined ($_ = shift @lines) && $_ =~ /^\t/)
	      {
		$paragraph .= "\n$_";
	      }
	    unshift (@lines, $_);
	  }

	# If we are a comments, eat as much comments as you can.
	elsif (/$COMMENT_PATTERN/smo)
	  {
	    while (defined ($_ = shift @lines)
		   && $_ =~ /$COMMENT_PATTERN/smo)
	      {
		$paragraph .= "\n$_";
	      }
	    unshift (@lines, $_);
	  }

	push @res, $paragraph;
	$paragraph = '';
      }

    return @res;
}



# ($COMMENT, $VARIABLES, $RULES)
# &file_contents_internal ($BASENAME, [%TRANSFORM])
# -------------------------------------------------
# Return contents of a file from $am_dir, automatically skipping
# macros or rules which are already known.
sub file_contents_internal ($%)
{
    my ($basename, %transform) = @_;
    my $file = $am_dir . '/' . $basename . '.am';

    # A rule has three parts: a list of targets, a list of dependencies,
    # and optionally actions.
    my $RULE_PATTERN =
      "^($TARGET_PATTERN(?:(?:\\\\\n|\\s)+$TARGET_PATTERN)*) *:([^=].*|)\$";

    my $result_vars = '';
    my $result_rules = '';
    my $comment = '';
    my $spacing = '';

    # We save the conditional stack on entry, and then check to make
    # sure it is the same on exit.  This lets us conditonally include
    # other files.
    my @saved_cond_stack = @cond_stack;
    my $cond = conditional_string (@cond_stack);

    foreach (make_paragraphs ($file, %transform))
    {
        # Sanity checks.
	&am_file_error ("$basename.am",
			"blank line following trailing backslash:\n$_")
	  if /\\$/;
	&am_file_error ("$basename.am",
			"comment following trailing backslash:\n$_")
	  if /\\#/;

 	if (/^$/)
 	{
 	    # Stick empty line before the incoming macro or rule.
 	    $spacing = "\n";
 	}
 	elsif (/$COMMENT_PATTERN/mso)
 	{
 	    # Stick comments before the incoming macro or rule.
 	    $comment = "$_\n";
	}

	# Handle inclusion of other files.
        elsif (/$INCLUDE_PATTERN/o)
        {
	    if ($cond ne 'FALSE')
	      {
		(my $file = $1) =~ s/\.am$//g;

		# N-ary `.=' fails.
		my ($com, $vars, $rules)
		  = file_contents_internal ($file, %transform);
		$comment .= $com;
		$result_vars .= $vars;
		$result_rules .= $rules;
	      }
        }

        # Handling the conditionals.
        elsif (/$IF_PATTERN/o)
	  {
	    $cond = cond_stack_if ($1, $2, $basename);
	  }
	elsif (/$ELSE_PATTERN/o)
	  {
	    $cond = cond_stack_else ($1, $2, $basename);
	  }
	elsif (/$ENDIF_PATTERN/o)
	  {
	    $cond = cond_stack_endif ($1, $2, $basename);
	  }

        # Handling rules.
 	elsif (/$RULE_PATTERN/mso)
 	{
	  # Separate relationship from optional actions: the first
	  # `new-line tab" not preceded by backslash (continuation
	  # line).
	  # I'm quite shoked!  It seems that (\\\n|[^\n]) is not the
	  # same as `([^\n]|\\\n)!!!  Don't swap it, it breaks.
	  my $paragraph = $_;
	  /^((?:\\\n|[^\n])*)(?:\n(\t.*))?$/som;
	  my ($relationship, $actions) = ($1, $2 || '');

	  # Separate targets from dependencies: the first colon.
	  $relationship =~ /^([^:]+\S+) *: *(.*)$/som;
	  my ($targets, $dependencies) = ($1, $2);
	  # Remove the escaped new lines.
	  # I don't know why, but I have to use a tmp $flat_deps.
	  my $flat_deps = &flatten ($dependencies);
	  my @deps = split (' ', $flat_deps);

	  foreach (split (' ' , $targets))
	    {
	      # FIXME: We are not robust to people defining several targets
	      # at once, only some of them being in %dependencies.

	      # Output only if not in FALSE.
	      if (defined $dependencies{$_}
		  && $cond ne 'FALSE')
		{
		  &depend ($_, @deps);
		  $actions{$_} .= $actions;
		}
	      else
		{
		  # Free lance dependency.  Output the rule for all the
		  # targets instead of one by one.
		  if (!defined $targets{$targets}
		      && $cond ne 'FALSE')
		    {
		      $result_rules .= "$spacing$comment$paragraph\n";
		      rule_define ($targets, 1, $cond, $.);
		    }
		  $comment = $spacing = '';
		  last;
		}
	    }
 	}
 	elsif (/$MACRO_PATTERN/mso)
 	{
	    my ($var, $type, $val) = ($1, $2, $3);
 	    &prog_error ("$file:$.: macro `$var' with trailing backslash")
	      if /\\$/;;

	    # Accumulating variables must not be output.
	    $var_comment{$var} .= "$spacing"
	      if (!defined $var_comment{$var}
		  || substr ($var_comment{$var}, -1) ne "\n");
	    $var_comment{$var} .= "$comment";
	    # Strip the continuation backslashes.
	    $val =~ s/\\$//mg;
	    macro_define ($var, 1, $type, $cond, $val, $.)
	      if $cond ne 'FALSE';
	    push (@var_list, $var);

	    # If the user has set some variables we were in charge
	    # of (which is detected by the first reading of
	    # `header-vars.am'), we must not output them.
	    $result_vars .= "$spacing$comment$_\n"
	      if $type ne '+' && $var_is_am{$var} && $cond ne 'FALSE';

 	    $comment = $spacing = '';
 	}
 	else
 	{
	    # This isn't an error; it is probably some tokens which
	    # configure is supposed to replace, such as `@SET-MAKE@',
	    # or some part of a rule cut by an if/endif.
  	    if ($cond ne 'FALSE')
	      {
		$result_rules .= "$spacing$comment$_\n";
	      }
 	    $comment = $spacing = '';
 	}
    }

    if (join (' ', @saved_cond_stack) ne join (' ', @cond_stack))
    {
	if (@cond_stack)
	{
	    &am_error ("unterminated conditionals: @cond_stack");
	}
	else
	{
	    # FIXME: better error message here.
	    &am_error ("conditionals not nested in include file");
	}
    }

    return ($comment, $result_vars, $result_rules);
}


# $CONTENTS
# &file_contents ($BASENAME, [%TRANSFORM])
# ----------------------------------------
# Return contents of a file from $am_dir, automatically skipping
# macros or rules which are already known.
sub file_contents ($%)
{
    my ($basename, %transform) = @_;
    my ($comments, $variables, $rules) = file_contents_internal ($basename,
								 %transform);
    return "$comments$variables$rules";
}


# $REGEXP
# &transform (%PAIRS)
# -------------------
# Foreach ($TOKEN, $VAL) in %PAIRS produce a replacement expression suitable
# for file_contents which:
#   - replaces @$TOKEN@ with $VALUE,
#   - enables/disables ?$TOKEN?.
sub transform (%)
{
    my (%pairs) = @_;
    my $result = '';

    while (my ($token, $val) = each %pairs)
    {
        $result .= "s/\Q%$token%\E/\Q$val\E/gm;";
	if ($val)
	{
	    $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
	    $result .= "s/\Q%?$token%\E/TRUE/gm;";
	}
	else
	{
	    $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
	    $result .= "s/\Q%?$token%\E/FALSE/gm;";
	}
    }

    return $result;
}


# Find all variable prefixes that are used for install directories.  A
# prefix `zar' qualifies iff:
# * `zardir' is a variable.
# * `zar_PRIMARY' is a variable.
sub am_primary_prefixes
{
    my ($primary, $can_dist, @prefixes) = @_;

    my %valid;
    grep ($valid{$_} = 0, @prefixes);
    $valid{'EXTRA'} = 0;
    foreach my $varname (keys %var_value)
    {
        # Automake is allowed to define variables that look like they
        # are magic variables, such as INSTALL_DATA.
        next
	  if $var_is_am{$varname};

	if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
	{
	    my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
	    if ($dist ne '' && ! $can_dist)
	    {
		# Note that a configure variable is always legitimate.
		# It is natural to name such variables after the
		# primary, so we explicitly allow it.
		if (! defined $configure_vars{$varname})
		{
		    &am_line_error ($varname,
				    "invalid variable `$varname': `dist' is forbidden");
		}
	    }
	    elsif (! defined $valid{$X} && ! &variable_defined ("${X}dir"))
	    {
		# Note that a configure variable is always legitimate.
		# It is natural to name such variables after the
		# primary, so we explicitly allow it.
		if (! defined $configure_vars{$varname})
		{
		    &am_line_error ($varname,
				    "invalid variable `$varname'");
		}
	    }
	    else
	    {
		# Ensure all extended prefixes are actually used.
		$valid{"$base$dist$X"} = 1;
	    }
	}
    }

    return %valid;
}

# Handle `where_HOW' variable magic.  Does all lookups, generates
# install code, and possibly generates code to define the primary
# variable.  The first argument is the name of the .am file to munge,
# the second argument is the primary variable (eg HEADERS), and all
# subsequent arguments are possible installation locations.  Returns
# list of all values of all _HOW targets.
#
# FIXME: this should be rewritten to be cleaner.  It should be broken
# up into multiple functions.
#
# Usage is: am_install_var (OPTION..., file, HOW, where...)
sub am_install_var
{
    my (@args) = @_;

    my $do_require = 1;
    my $can_dist = 0;
    my $default_dist = 0;
    while (@args)
    {
	if ($args[0] eq '-noextra')
	{
	    $do_require = 0;
	}
	elsif ($args[0] eq '-candist')
	{
	    $can_dist = 1;
	}
	elsif ($args[0] eq '-defaultdist')
	{
	    $default_dist = 1;
	    $can_dist = 1;
	}
	elsif ($args[0] !~ /^-/)
	{
	    last;
	}
	shift (@args);
    }

    my ($file, $primary, @prefixes) = @args;

    # Now that configure substitutions are allowed in where_HOW
    # variables, it is an error to actually define the primary.  We
    # allow `JAVA', as it is customarily used to mean the Java
    # interpreter.  This is but one of several Java hacks.  Similarly,
    # `PYTHON' is customarily used to mean the Python interpreter.
    &am_line_error ($primary, "`$primary' is an anachronism")
	if &variable_defined ($primary)
	    && ($primary ne 'JAVA' && $primary ne 'PYTHON');


    # Look for misspellings.  It is an error to have a variable ending
    # in a "reserved" suffix whose prefix is unknown, eg
    # "bni_PROGRAMS".  However, unusual prefixes are allowed if a
    # variable of the same name (with "dir" appended) exists.  For
    # instance, if the variable "zardir" is defined, then
    # "zar_PROGRAMS" becomes valid.  This is to provide a little extra
    # flexibility in those cases which need it.
    my %valid = &am_primary_prefixes ($primary, $can_dist, @prefixes);

    # If a primary includes a configure substitution, then the EXTRA_
    # form is required.  Otherwise we can't properly do our job.
    my $require_extra;
    my $warned_about_extra = 0;

    my @used = ();
    my @result = ();

    # True if the iteration is the first one.  Used for instance to
    # output parts of the associated file only once.
    my $first = 0;
    foreach my $X (sort keys %valid)
    {
	my $one_name = $X . '_' . $primary;
	if (&variable_defined ($one_name))
	{
	    my $strip_subdir = 1;
	    # If subdir prefix should be preserved, do so.
	    if ($X =~ /^nobase_/)
	    {
		$strip_subdir = 0;
		$X =~ s/^nobase_//;
	    }

	    my $nodir_name = $X;
	    # If files should be distributed, do so.
	    my $dist_p = 0;
	    if ($can_dist)
	    {
	        $dist_p = (($default_dist && $one_name !~ /^nodist_/)
			   || (! $default_dist && $one_name =~ /^dist_/));
		$nodir_name =~ s/^(dist|nodist)_//;
	    }

	    # Append actual contents of where_PRIMARY variable to
	    # result.
	    foreach my $rcurs (&variable_value_as_list ($one_name, 'all'))
	    {
		# Skip configure substitutions.  Possibly bogus.
		if ($rcurs =~ /^\@.*\@$/)
		{
		    if ($X eq 'EXTRA')
		    {
			if (! $warned_about_extra)
			{
			    $warned_about_extra = 1;
			    &am_line_error ($one_name,
					    "`$one_name' contains configure substitution, but shouldn't");
			}
		    }
		    # Check here to make sure variables defined in
		    # configure.ac do not imply that EXTRA_PRIMARY
		    # must be defined.
		    elsif (! defined $configure_vars{$one_name})
		    {
			$require_extra = $one_name
			    if $do_require;
		    }

		    next;
		}

		push (@result, $rcurs);
	    }

	    # A blatant hack: we rewrite each _PROGRAMS primary to
	    # include EXEEXT when in Cygwin32 mode.
	    if ($primary eq 'PROGRAMS')
	    {
		my @conds = &variable_conditions ($one_name);

		my @condvals;
		foreach my $cond (@conds)
		  {
		    my @one_binlist = ();
		    my @condval = &variable_value_as_list ($one_name,
							   $cond);
		    foreach my $rcurs (@condval)
		      {
			if ($rcurs =~ /\./ || $rcurs =~ /^\@.*\@$/)
			  {
			    push (@one_binlist, $rcurs);
			  }
			else
			  {
			    push (@one_binlist, $rcurs . '$(EXEEXT)');
			  }
		      }

		    push (@condvals, $cond);
		    push (@condvals, join (' ', @one_binlist));
		  }

		variable_delete ($one_name);
		while (@condvals)
		  {
		    my $cond = shift (@condvals);
		    my @val = split (' ', shift (@condvals));
		    &define_pretty_variable ($one_name, $cond, @val);
		  }
	    }

	    # "EXTRA" shouldn't be used when generating clean targets,
	    # all, or install targets.
	    if ($X eq 'EXTRA')
	    {
		# We used to warn if EXTRA_FOO was defined uselessly,
		# but this was annoying.
		next;
	    }

	    if ($X eq 'check')
	    {
		push (@check, '$(' . $one_name . ')');
	    }
	    else
	    {
		push (@used, '$(' . $one_name . ')');
	    }

	    # Is this to be installed?
	    my $install_p = $X ne 'noinst' && $X ne 'check';

	    # If so, with install-exec? (or install-data?).
	    my $exec_p = (defined $exec_dir_p {$X}
			  ? $exec_dir_p {$X}
			  : ($X =~ /exec/));

	    # Singular form of $PRIMARY.
	    (my $one_primary = $primary) =~ s/S$//;
	    $output_rules .= &file_contents ($file,
					     ('FIRST' => $first,

					      'PRIMARY'     => $primary,
					      'ONE_PRIMARY' => $one_primary,
					      'DIR'         => $X,
					      'NDIR'        => $nodir_name,
					      'BASE'        => $strip_subdir,

					      'EXEC'    => $exec_p,
					      'INSTALL' => $install_p,
					      'DIST'    => $dist_p));

	    $first = '';
	}
    }

    # The JAVA variable is used as the name of the Java interpreter.
    # The PYTHON variable is used as the name of the Python interpreter.
    if (@used && $primary ne 'JAVA' && $primary ne 'PYTHON')
    {
	# Define it.
	&define_pretty_variable ($primary, '', @used);
	$output_vars .= "\n";
    }

    if ($require_extra && ! &variable_defined ('EXTRA_' . $primary))
    {
	&am_line_error ($require_extra,
			"`$require_extra' contains configure substitution, but `EXTRA_$primary' not defined");
    }

    # Push here because PRIMARY might be configure time determined.
    push (@all, '$(' . $primary . ')')
	if @used && $primary ne 'JAVA' && $primary ne 'PYTHON';

    # Make the result unique.  This lets the user use conditionals in
    # a natural way, but still lets us program lazily -- we don't have
    # to worry about handling a particular object more than once.
    return uniq (sort @result);
}


################################################################

# Each key in this hash is the name of a directory holding a
# Makefile.in.  These variables are local to `is_make_dir'.
my %make_dirs = ();
my $make_dirs_set = 0;

sub is_make_dir
{
    my ($dir) = @_;
    if (! $make_dirs_set)
    {
	foreach my $iter (@configure_input_files)
	{
	    $make_dirs{dirname ($iter)} = 1;
	}
	# We also want to notice Makefile.in's.
	foreach my $iter (@other_input_files)
	{
	    if ($iter =~ /Makefile\.in$/)
	    {
		$make_dirs{dirname ($iter)} = 1;
	    }
	}
	$make_dirs_set = 1;
    }
    return defined $make_dirs{$dir};
}

################################################################

# This variable is local to the "require file" set of functions.
my @require_file_paths = ();

# If a file name appears as a key in this hash, then it has already
# been checked for.  This variable is local to the "require file"
# functions.
%require_file_found = ();

# See if we want to push this file onto dist_common.  This function
# encodes the rules for deciding when to do so.
sub maybe_push_required_file
{
    my ($dir, $file, $fullfile) = @_;

    # FIXME: Once again, special-case `.'.
    if ($dir eq $relative_dir || $dir eq '.')
    {
	&push_dist_common ($file);
    }
    elsif ($relative_dir eq '.' && ! &is_make_dir ($dir))
    {
	# If we are doing the topmost directory, and the file is in a
	# subdir which does not have a Makefile, then we distribute it
	# here.
	&push_dist_common ($fullfile);
    }
}


# &require_file_internal ($IS_CONFIGURE, $LINE, $MYSTRICT, @FILES)
# ----------------------------------------------------------------
# Verify that the file must exist in the current directory.
# $MYSTRICT is the strictness level at which this file becomes required.
#
# Must set require_file_paths before calling this function.
# require_file_paths is set to hold a single directory (the one in
# which the first file was found) before return.
sub require_file_internal
{
    my ($is_configure, $line, $mystrict, @files) = @_;

    foreach my $file (@files)
    {
        my $fullfile;
	my $errdir;
	my $errfile;
	my $save_dir;

	# If we've already looked for it, we're done.
	next if defined $require_file_found{$file};
	$require_file_found{$file} = 1;

	my $found_it = 0;
	my $dangling_sym = 0;
	foreach my $dir (@require_file_paths)
	{
	    if ($dir eq '.')
	    {
		$fullfile = $relative_dir . "/" . $file;
		$errdir = $relative_dir unless $errdir;
	    }
	    else
	    {
		$fullfile = $dir . "/" . $file;
		$errdir = $dir unless $errdir;
	    }

	    # Use different name for "error filename".  Otherwise on
	    # an error the bad file will be reported as eg
	    # `../../install-sh' when using the default
	    # config_aux_path.
	    $errfile = $errdir . '/' . $file;

	    if (-l $fullfile && ! -f readlink ($fullfile))
	    {
		$dangling_sym = 1;
		last;
	    }
	    elsif (-f $fullfile)
	    {
		$found_it = 1;
		&maybe_push_required_file ($dir, $file, $fullfile);
		$save_dir = $dir;
		last;
	    }
	}

	if ($found_it && ! $force_missing)
	{
	    # Prune the path list.
	    @require_file_paths = $save_dir;
	}
	else
	{
	    if ($strictness >= $mystrict)
	    {
		if ($dangling_sym && ($force_missing || $add_missing))
		{
		    unlink ($fullfile);
		}

		my $trailer = '';
		my $suppress = 0;

		# Only install missing files according to our desired
		# strictness level.
		my $message = "required file `$errfile' not found";
		if ($add_missing)
		{
		    $suppress = 1;

		    # Maybe run libtoolize.
		    my @syslist = ('libtoolize', '--automake');
		    push @syslist, '--copy'
			if $copy_missing;
		    if ($seen_libtool
			&& grep ($_ eq $file, @libtoolize_files)
			&& system (@syslist))
		    {
			$message = "installing `$errfile'";
			$suppress = 0;
			$trailer = "; cannot run `libtoolize': $!";
		    }
		    elsif (-f ("$pkgdata_dir/$file"))
		    {
			# Install the missing file.  Symlink if we
			# can, copy if we must.  Note: delete the file
			# first, in case it is a dangling symlink.
			$message = "installing `$errfile'";
			# Windows Perl will hang if we try to delete a
			# file that doesn't exist.
			unlink ($errfile) if -f $errfile;
			if ($symlink_exists && ! $copy_missing)
			{
			    if (! symlink ("$pkgdata_dir/$file", $errfile))
			    {
				$suppress = 0;
				$trailer = "; error while making link: $!";
			    }
			}
			elsif (system ('cp', "$pkgdata_dir/$file", $errfile))
			{
			    $suppress = 0;
			    $trailer = "\n    error while copying";
			}
		    }

		    &maybe_push_required_file (dirname ($errfile),
					       $file, $errfile);
		}

		my $save = $exit_status;
		if ($is_configure)
		{
		    # FIXME: allow actual file to be specified.
		    &am_conf_line_error ($configure_ac, $line,
					 "$message$trailer");
		}
		else
		{
		    &am_line_error ($line, "$message$trailer");
		}
		$exit_status = $save if $suppress;
	    }
	}
    }
}

# Like require_file_with_line, but error messages refer to
# configure.ac, not the current Makefile.am.
sub require_file_with_conf_line
{
    @require_file_paths = '.';
    &require_file_internal (1, @_);
}

sub require_file_with_line
{
    @require_file_paths = '.';
    &require_file_internal (0, @_);
}

sub require_file
{
    @require_file_paths = '.';
    &require_file_internal (0, '', @_);
}

# Require a file that is also required by Autoconf.  Looks in
# configuration path, as specified by AC_CONFIG_AUX_DIR.
sub require_config_file
{
    @require_file_paths = @config_aux_path;
    &require_file_internal (1, '', @_);
    my $dir = $require_file_paths[0];
    @config_aux_path = @require_file_paths;
    if ($dir eq '.')
    {
	$config_aux_dir = '.';
    }
    else
    {
	$config_aux_dir = '$(top_srcdir)/' . $dir;
    }
}

# Assumes that the line number is in Makefile.am.
sub require_conf_file_with_line
{
    @require_file_paths = @config_aux_path;
    &require_file_internal (0, @_);
    my $dir = $require_file_paths[0];
    @config_aux_path = @require_file_paths;
    if ($dir eq '.')
    {
	$config_aux_dir = '.';
    }
    else
    {
	$config_aux_dir = '$(top_srcdir)/' . $dir;
    }
}

# Assumes that the line number is in configure.ac.
sub require_conf_file_with_conf_line
{
    @require_file_paths = @config_aux_path;
    &require_file_internal (1, @_);
    my $dir = $require_file_paths[0];
    @config_aux_path = @require_file_paths;
    if ($dir eq '.')
    {
	$config_aux_dir = '.';
    }
    else
    {
	$config_aux_dir = '$(top_srcdir)/' . $dir;
    }
}

################################################################

# Push a list of files onto dist_common.
sub push_dist_common
{
    &prog_error ("push_dist_common run after handle_dist")
        if $handle_dist_run;
    macro_define ('DIST_COMMON', 1, '+', '', join (' ', @_), '');
}


# Set strictness.
sub set_strictness
{
    $strictness_name = $_[0];
    if ($strictness_name eq 'gnu')
    {
	$strictness = $GNU;
    }
    elsif ($strictness_name eq 'gnits')
    {
	$strictness = $GNITS;
    }
    elsif ($strictness_name eq 'foreign')
    {
	$strictness = $FOREIGN;
    }
    else
    {
	die "$me: level `$strictness_name' not recognized\n";
    }
}


################################################################

# Ensure a file exists.
sub create
{
    my ($file) = @_;

    my $touch = new IO::File (">> $file");
    $touch->close;
}

# Glob something.  Do this to avoid indentation screwups everywhere we
# want to glob.  Gross!
sub my_glob
{
    my ($pat) = @_;
    return <${pat}>;
}

# Remove one level of brackets and strip leading spaces,
# as does m4 to function arguments.
sub unquote_m4_arg
{
    $_ = shift;
    s/^\s*//;

    my @letters = split //;
    my @result = ();
    my $depth = 0;

    foreach (@letters)
    {
	if ($_ eq '[')
	{
	    ++$depth;
	    next if $depth == 1;
	}
	elsif ($_ eq ']')
	{
	    --$depth;
	    next if $depth == 0;
	    # don't count orphan right brackets
	    $depth = 0 if $depth < 0;
	}
	push @result, $_;
    }
    return join '', @result;
}

################################################################

# Print an error message and set exit status.
sub am_error
{
    warn "$me: ${am_file}.am: @_\n";
    $exit_status = 1;
}


# am_file_error ($FILE, @ARGS)
# ----------------------------
sub am_file_error
{
    my ($file, @args) = @_;

    warn "$file: @args\n";
    $exit_status = 1;
}

sub am_line_error
{
    my ($symbol, @args) = @_;

    if ($symbol && "$symbol" ne '-1')
    {
	my $file = "${am_file}.am";

	if ($symbol =~ /^\d+$/)
	{
	    # SYMBOL is a line number, so just add the colon.
	    $file .= ':' . $symbol;
	}
	elsif (defined $var_line{$symbol})
	{
	    # SYMBOL is a variable defined in Makefile.am, so add the
	    # line number we saved from there.
	    $file .= ':' . $var_line{$symbol};
	}
	elsif (defined $configure_vars{$symbol})
	{
	    # SYMBOL is a variable defined in configure.ac, so add the
	    # appropriate line number.
	    $file = $configure_vars{$symbol};
	}
	else
	{
	    # Couldn't find the line number.
	}
	warn $file, ": @args\n";
	$exit_status = 1;
    }
    else
    {
	&am_error (@args);
    }
}

# Like am_error, but while scanning configure.ac.
sub am_conf_error
{
    # FIXME: can run in subdirs.
    warn "$me: $configure_ac: @_\n";
    $exit_status = 1;
}

# Error message with line number referring to configure.ac.
sub am_conf_line_error
{
    my ($file, $line, @args) = @_;

    if ($line)
    {
	warn "$file: $line: @args\n";
	$exit_status = 1;
    }
    else
    {
	&am_conf_error (@args);
    }
}

# Warning message with line number referring to configure.ac.
# Does not affect exit_status
sub am_conf_line_warning
{
    my $saved_exit_status = $exit_status;
    &am_conf_line_error (@_);
    $exit_status = $saved_exit_status;
}

# Tell user where our aclocal.m4 is, but only once.
sub keyed_aclocal_warning
{
    my ($key) = @_;
    warn "$me: macro `$key' can be generated by `aclocal'\n";
}

# Print usage information.
sub usage
{
    print <<EOF;
Usage: $0 [OPTION] ... [Makefile]...

Generate Makefile.in for configure from Makefile.am.

Operation modes:
      --help             print this help, then exit
      --version          print version number, then exit
  -v, --verbose          verbosely list files processed
  -o, --output-dir=DIR   put generated Makefile.in's into DIR
      --no-force         only update Makefile.in's that are out of date

Dependency tracking:
  -i, --ignore-deps      disable dependency tracking code
      --include-deps     enable dependency tracking code

Flavors:
      --cygnus           assume program is part of Cygnus-style tree
      --foreign          set strictness to foreign
      --gnits            set strictness to gnits
      --gnu              set strictness to gnu

Library files:
  -a, --add-missing      add missing standard files to package
      --amdir=DIR        directory storing config files
  -c, --copy             with -a, copy missing files (default is symlink)
  -f, --force-missing    force update of standard files
EOF

    my ($last, @lcomm);
    $last = '';
    foreach my $iter (sort ((@common_files, @common_sometimes)))
    {
	push (@lcomm, $iter) unless $iter eq $last;
	$last = $iter;
    }

    my ($one, $two, $three, $four, $max);
    print "\nFiles which are automatically distributed, if found:\n";
    format USAGE_FORMAT =
  @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
  $one,               $two,               $three,             $four
.
    $~ = "USAGE_FORMAT";
    $max = int (($#lcomm + 1) / 4);

    for (my $i = 0; $i < $max; ++$i)
    {
	$one = $lcomm[$i];
	$two = $lcomm[$max + $i];
	$three = $lcomm[2 * $max + $i];
	$four = $lcomm[3 * $max + $i];
	write;
    }

    my $mod = ($#lcomm + 1) % 4;
    if ($mod != 0)
    {
	$one = $lcomm[$max];
	$two = ($mod > 1) ? $lcomm[2 * $max] : '';
	$three = ($mod > 2) ? $lcomm[3 * $max] : '';
	$four = ($mod > 3) ? $lcomm[4 * $max] : '';
	write;
    }

    print "\nReport bugs to <bug-automake\@gnu.org>.\n";

    exit 0;
}

# &version ()
# -----------
# Print version information
sub version ()
{
  print <<EOF;
automake (GNU $PACKAGE) $VERSION
Written by Tom Tromey <tromey\@cygnus.com>.

Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
  exit 0;
}