summaryrefslogtreecommitdiff
path: root/automake.in
blob: d4e0da00f6e9a9992e49911a16acf7cc96cc9f5a (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
#!@PERL@
# -*- perl -*-
# @configure_input@

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

# automake - create Makefile.in from Makefile.am
# Copyright (C) 1994, 1995, 1996 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>.


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

# String constants.
$IGNORE_PATTERN = "^##([^#].*)?\$";
$WHITE_PATTERN = "^[ \t]*\$";
$COMMENT_PATTERN = "^#";
$RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/]*) *:([^=].*|)\$";
$MACRO_PATTERN = "^([A-Za-z][A-Za-z0-9_]*)[ \t]*:?=[ \t]*(.*)\$";
$BOGUS_MACRO_PATTERN = "^([^ \t]*)[ \t]*:?=[ \t]*(.*)\$";
$GNITS_VERSION_PATTERN = "[0-9]+\\.[0-9]+([a-z]|\\.[0-9]+)?";

# Some regular expressions.  One reason to put them here is that it
# makes indentation work better in Emacs.
$AC_CONFIG_AUX_DIR_PATTERN = "AC_CONFIG_AUX_DIR\\(([^)]+)\\)";
$AM_INIT_AUTOMAKE_PATTERN = "AM_INIT_AUTOMAKE\\([^,]*,([^)]+)\\)";
$AM_PACKAGE_VERSION_PATTERN = "^\\s*\\[?([^]\\s]+)\\]?\\s*\$";
# Note that there is no AC_PATH_TOOL.  But we don't really care.
$AC_CHECK_PATTERN = "AC_(CHECK|PATH)_(PROG|PROGS|TOOL)\\(\\[?([^]),]+)";
$AC_SUBST_PATTERN = "AC_SUBST\\(\\[?([^])]+)";

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



# Variables global to entire run.

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

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

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

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

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

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

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

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

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

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

# Names used in AC_CONFIG_HEADER call.  $config_name is the actual
# (first) argument.  $config_header is the '.in' file.  Ordinarily the
# second is derived from the first, but they can be different if the
# weird "NAME:FILE" syntax is used.
$config_name = '';
$config_header = '';
# Line number at which AC_CONFIG_HEADER appears in configure.in.
$config_header_line = 0;

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

# Relative location of top build directory.
$top_builddir = '';

# Absolute location of top build directory.
$build_directory = '';

# Name of srcdir as given in build directory's Makefile.  For
# dependencies only.
$srcdir_name = '';

# List of Makefile.am's to process.
@input_files = ();

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

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

# Whether AC_PROG_MAKE_SET has been seen in configure.in.
$seen_make_set = 0;

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

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

# 1 if AC_PROG_INSTALL seen, 2 if AM_PROG_INSTALL seen.
$seen_prog_install = 0;

# 1 if any scripts installed, 0 otherwise.
$scripts_installed = 0;

# Whether AC_PATH_XTRA has been seen in configure.in.
$seen_path_xtra = 0;

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

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

# TRUE if we've seen AC_ARG_PROGRAM.
$seen_arg_prog = 0;

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

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

# TRUE if we've seen PACKAGE and VERSION.
$seen_package = 0;
$seen_version = 0;

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

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

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

# Hash table of discovered configure substitutions.  Keys are names,
# values are meaningless.
%configure_vars = ();

# 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?
$maint_charset = '';
$dist_charset = 'utf8';		# recode doesn't support this yet.

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

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

# Keys of this hash are names of dependency files to ignore.
%omit_dependencies = ();



&initialize_global_constants;

# Parse command line.
&parse_arguments (@ARGV);

# Do configure.in scan only once.
&scan_configure;

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

# Now do all the work on each file.
foreach $am_file (@input_files)
{
    # FIXME: should support the AC_OUTPUT ":" syntax here.
    if (! -f ($am_file . '.am'))
    {
	&am_error ('no such file');
    }
    else
    {
	&generate_makefile ($am_file);
    }
}

if ($seen_prog_install <= $scripts_installed)
{
    &am_conf_error (($scripts_installed ? 'AM_PROG_INSTALL' : 'AC_PROG_INSTALL')
		    . " must be used in configure.in");
    &keyed_aclocal_warning ('AM_PROG_INSTALL')
	if $scripts_installed;
}

exit $exit_status;


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

# Parse command line.
sub parse_arguments
{
    local (@arglist) = @_;

    # Start off as gnu.
    &set_strictness ('gnu');

    while (@arglist)
    {
	if ($arglist[0] eq "--version")
	{
	    print "automake (GNU $PACKAGE) $VERSION\n";
	    print "Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.\n";
	    print "automake comes with ABSOLUTELY NO WARRANTY.\n";
	    print "You may redistribute copies of automake\n";
	    print "under the terms of the GNU General Public License.\n";
	    print "For more information about these matters, see the file named COPYING.\n";
	    exit 0;
	}
	elsif ($arglist[0] eq "--help")
	{
	    &usage;
	}
	elsif ($arglist[0] =~ /^--amdir=(.+)$/)
	{
	    $am_dir = $1;
	}
	elsif ($arglist[0] eq '--amdir')
	{
	    &require_argument (@arglist);
	    shift (@arglist);
	    $am_dir = $arglist[0];
	}
	elsif ($arglist[0] =~ /^--build-dir=(.+)$/)
	{
	    # Must end in /.
	    $build_directory = $1 . '/';
	}
	elsif ($arglist[0] eq '--build-dir')
	{
	    &require_argument (@arglist);
	    shift (@arglist);
	    # Must end in /.
	    $build_directory = $arglist[0] . '/';
	}
	elsif ($arglist[0] =~ /^--srcdir-name=(.+)$/)
	{
	    $srcdir_name = $1;
	}
	elsif ($arglist[0] eq '--srcdir-name')
	{
	    &require_argument (@arglist);
	    shift (@arglist);
	    $srcdir_name = $arglist[0];
	}
	elsif ($arglist[0] =~ /^--strictness=(.+)$/)
	{
	    &set_strictness ($1);
	}
	elsif ($arglist[0] eq '--gnu')
	{
	    &set_strictness ('gnu');
	}
	elsif ($arglist[0] eq '--gnits')
	{
	    &set_strictness ('gnits');
	}
	elsif ($arglist[0] eq '--cygnus')
	{
	    $cygnus_mode = 1;
	}
	elsif ($arglist[0] eq '--foreign')
	{
	    &set_strictness ('foreign');
	}
	elsif ($arglist[0] eq '--strictness' || $arglist[0] eq '-s')
	{
	    &require_argument (@arglist);
	    shift (@arglist);
	    &set_strictness ($arglist[0]);
	}
	elsif ($arglist[0] eq '--include-deps' || $arglist[0] eq '-i')
	{
	    $cmdline_use_dependencies = 0;
	}
	elsif ($arglist[0] eq '--no-force')
	{
	    $force_generation = 0;
	}
	elsif ($arglist[0] =~ /^--output-dir=(.*)$/)
	{
	    # Set output directory.
	    $output_directory = $1;
	}
	elsif ($arglist[0] eq '--output-dir' || $arglist[0] eq '-o')
	{
	    &require_argument (@arglist);
	    shift (@arglist);
	    $output_directory = $arglist[0];
	}
	elsif ($arglist[0] eq '--add-missing' || $arglist[0] eq '-a')
	{
	    $add_missing = 1;
	}
	elsif ($arglist[0] eq '--verbose' || $arglist[0] eq '-v')
	{
	    $verbose = 1;
	}
	elsif ($arglist[0] eq '--')
	{
	    # Stop option processing.
	    shift (@arglist);
	    push (@input_files, @arglist);
	    last;
	}
	elsif ($arglist[0] =~ /^-/)
	{
	    die "automake: unrecognized option -- \`$arglist[0]'\nTry \`automake --help' for more information.\n";
	}
	else
	{
	    push (@input_files, $arglist[0]);
	}

	shift (@arglist);
    }

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

# Ensure argument exists, or die.
sub require_argument
{
    local ($arg, @arglist) = @_;
    die "automake: no argument given for option \`$arg'\n"
	if ! @arglist;
}

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

# Generate a Makefile.in given the name of the corresponding Makefile.
sub generate_makefile
{
    local ($makefile) = @_;

    ($am_file_name = $makefile) =~ s/^.*\///;
    $in_file_name = $am_file_name . '.in';
    $am_file_name .= '.am';

    &initialize_per_input;
    $relative_dir = &dirname ($makefile);

    # 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,
 					   'config.sub', 'config.guess',
 					   'ltconfig', 'ltmain.sh')
	    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.
    &push_dist_common ($in_file_name, $am_file_name);
    push (@sources, '$(SOURCES)')
	if &variable_defined ('SOURCES');
    push (@objects, '$(OBJECTS)')
	if &variable_defined ('OBJECTS');

    # This is always the default target.  This gives us freedom to do
    # things in whatever order is convenient.
    $output_rules .= "default: all\n\n";
    push (@phony, 'default');

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

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

    &handle_configure;
    &handle_gettext;
    &handle_libraries;
    &handle_programs;
    &handle_scripts;

    &handle_built_sources;

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

    # Re-init SOURCES and OBJECTS.  FIXME: other code shouldn't depend
    # on this (but currently does).
    $contents{'SOURCES'} = join (' ', @sources);
    $contents{'OBJECTS'} = join (' ', @objects);

    &handle_texinfo;
    &handle_emacs_lisp;
    &handle_man_pages;
    &handle_data;
    &handle_headers;
    &handle_subdirs;
    &handle_tags;
    &handle_dist;
    &handle_dependencies;
    &handle_tests;
    &handle_footer;
    &handle_merge_targets;
    &handle_installdirs;
    &handle_clean;
    &handle_phony;

    &check_typos;

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

    local ($out_file) = $output_directory . '/' . $makefile . ".in";
    if (! $force_generation && -e $out_file)
    {
	local ($am_time) = (stat ($makefile . '.am'))[9];
	local ($in_time) = (stat ($out_file))[9];
	# FIXME: how to do unsigned comparison?
	if ($am_time < $in_time)
	{
	    # No need to update.
	    return;
	}
    }

    if (! open (GM_FILE, "> " . $out_file))
    {
	warn "automake: ${am_file}.in: cannot open: $!\n";
	$exit_status = 1;
	return;
    }
    print "automake: creating ", $makefile, ".in\n" if $verbose;

    print GM_FILE $output_vars;
    print GM_FILE $output_rules;
    print GM_FILE $output_trailer;

    close (GM_FILE);
}

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

# Handle AUTOMAKE_OPTIONS variable.  Return 1 on error, 0 otherwise.
sub handle_options
{
    return 0 if ! &variable_defined ('AUTOMAKE_OPTIONS');

    foreach (&variable_value_as_list ('AUTOMAKE_OPTIONS'))
    {
	$options{$_} = 1;
	if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
	{
	    &set_strictness ($_);
	}
	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 'dejagnu')
	{
	    # Explicitly recognize these.
	}
	elsif ($_ eq 'no-dependencies')
	{
	    $use_dependencies = 0;
	}
	elsif (/([0-9]+)\.([0-9]+)/)
	{
	    # Got a version number.  Note that alpha releases count as
	    # the next higher release.  Note also that we assume there
	    # will be a maximum of 100 minor releases for any given
	    # major release.
	    local ($rmajor, $rminor) = ($1, $2);
	    if ($VERSION !~ /([0-9]+)\.([0-9]+)([a-z])?/)
	    {
		print STDERR
		    "automake: programming error: version is incorrect\n";
		exit 1;
	    }
	    local ($tmajor, $tminor) = ($1, $2);
	    # Handle alpha versions.
	    ++$tminor if defined $3;

	    if ($rmajor > $tmajor || ($rmajor == $tmajor && $rminor > $tminor))
	    {
		&am_line_error ('AUTOMAKE_OPTIONS',
				"require version $_, only have $VERSION");
		return 1;
	    }
	}
	else
	{
	    &am_line_error ('AUTOMAKE_OPTIONS',
			    'option ', $_, 'not recognized');
	}
    }

    return 0;
}

# Return object extension.  Just once, put some code into the output.
sub get_object_extension
{
    if (! $dir_holds_sources)
    {
	# Boilerplate.
	local ($xform) = '';
	if (&variable_defined ('CONFIG_HEADER'))
	{
	    ($xform = &dirname ($contents{'CONFIG_HEADER'}))
		=~ s/(\W)/\\$1/g;
	    $xform = '-I' . $xform;
	}
	$xform = 's/\@CONFIG_INCLUDE_SPEC\@/' . $xform . '/go';
	$output_vars .= &file_contents_with_transform ($xform,
						       'comp-vars');
	$output_rules .= &file_contents ('compile');
	&push_phony_cleaners ('compile');

	# 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 ($seen_path_xtra)
	{
	    local ($var);
	    foreach $var ('X_CFLAGS', 'X_LIBS', 'X_EXTRA_LIBS', 'X_PRE_LIBS')
	    {
		&define_configure_variable ($var);
	    }
	}

	# Check for automatic de-ANSI-fication.
	$dir_holds_sources = '.o';
	push (@suffixes, '.c', '.o');
	push (@clean, 'compile');

	if (defined $options{'ansi2knr'})
	{
	    if (! $am_c_prototypes)
	    {
		&am_line_error ('AUTOMAKE_OPTIONS',
				"option \`ansi2knr' in use but \`AM_C_PROTOTYPES' not in configure.in");
		&keyed_aclocal_warning ('AM_C_PROTOTYPES');
		# Only give this error once.
		$am_c_prototypes = 1;
	    }

	    $dir_holds_sources = '$o';
	    push (@suffixes, '._c', '._o');

	    # Only require ansi2knr files if they should appear in
	    # this directory.
	    if ($options{'ansi2knr'} eq 'ansi2knr')
	    {
		&require_file_with_line ('AUTOMAKE_OPTIONS', $FOREIGN,
					 'ansi2knr.c', 'ansi2knr.1');
		$output_rules .= &file_contents ('kr-extra');
		push (@clean, 'krextra');
		&push_phony_cleaners ('krextra');
	    }

	    &define_variable ('o', ".\@U\@o");

	    # Make sure ansi2knr can be found: if no path specified,
	    # specify "./".
	    local ($apath) = $options{'ansi2knr'};
	    if ($apath =~ /\//)
	    {
		# Found in another directory.
		&define_variable ("ANSI2KNR", $apath);
	    }
	    else
	    {
		# Substitution from AM_C_PROTOTYPES.  This makes it be
		# built only when necessary.
		&define_configure_variable ('ANSI2KNR');
		push (@all, '$(ANSI2KNR)');
	    }

	    $output_rules .= &file_contents ('compile-kr');
	    $output_rules .= &file_contents ('clean-kr');

	    push (@clean, 'kr');
	    &push_phony_cleaners ('kr');
	}
    }
    return $dir_holds_sources;
}

# Handle yacc and lex.
sub handle_yacc_lex_cxx
{
    #
    # First do yacc and lex.
    #

    local ($yacc_count) = scalar (keys %yacc_sources);
    local ($lex_count) = scalar (keys %lex_sources);
    if ($yacc_count)
    {
	push (@suffixes, '.y');
	$output_rules .= ".y.c:\n\t";
	if ($yacc_count > 1)
	{
	    $output_rules .= '$(SHELL) $(INTERLOCK) =yacclockdir $(YLWRAP) "$(YACC)" y.tab.c $*.c y.tab.h $*.h -- $(YFLAGS) $<';
	}
	else
	{
	    $output_rules .= ('$(YACC) $(YFLAGS) $< && mv y.tab.c $@' . "\n\t"
			      . 'if test -f y.tab.h; then mv y.tab.h $*.h; else :; fi');
	}
	$output_rules .= "\n";

	if (! defined $configure_vars{'YACC'})
	{
	    &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'");
	}
    }
    if ($lex_count)
    {
	push (@suffixes, '.l');
	&define_configure_variable ('LEX_OUTPUT_ROOT');
	&define_configure_variable ('LEXLIB');
	$output_rules .= ".l.c:\n\t";
	if ($lex_count > 1)
	{
	    $output_rules .= '$(SHELL) $(INTERLOCK) =lexlockdir $(YLWRAP) "$(LEX)" $(LEX_OUTPUT_ROOT).c $@ -- $(LFLAGS) $<';
	}
	else
	{
	    $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@';
	}
	$output_rules .= "\n";

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

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

    #
    # Now handle C++.
    #
    local (@cxx_list) = keys %cxx_extensions;
    local ($cxx_count) = scalar @cxx_list;
    if ($cxx_count)
    {
	push (@suffixes, @cxx_list);

	&define_configure_variable ("CXXFLAGS");
	&define_variable ('CXXCOMPILE', '$(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
	&define_variable ('CXXLINK', '$(CXX) $(LDFLAGS) -o $@');

	local ($ext);
	foreach $ext (@cxx_list)
	{
	    $output_rules .= ("$ext.o:\n"
			      . "\t\$(CXXCOMPILE) -c \$<\n");
	}

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

    #
    # Last, handle some C cleanup.
    #
    if ($seen_c_source)
    {
	&define_configure_variable ('CFLAGS');
	&define_variable ('COMPILE',
			  '$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)');
	&define_variable ('LINK', '$(CC) $(LDFLAGS) -o $@');

	if (! defined $configure_vars{'CC'})
	{
	    &am_error
		("C source seen but \`CC' not defined in \`configure.in'");
	}
    }
}

# 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
{
    local ($one_file, $unxformed) = @_;

    local ($prefix, $file, @files);
    foreach $prefix ('', 'EXTRA_')
    {
	if (&variable_defined ($prefix . $one_file . '_SOURCES'))
	{
	    @files = &variable_value_as_list ($prefix
					      . $one_file . '_SOURCES');
	}
	elsif ($prefix eq '')
	{
	    @files = ($unxformed . '.c');
	}
	else
	{
	    next;
	}

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

# Does much of the actual work for handle_source_transform.
# Arguments are:
#   list of source files to transform
# Result is a list
#   first element is name of linker to use (empty string for default linker)
#   remaining elements are names of `.o's
sub handle_single_transform_list
{
    local (@files) = @_;
    local ($linker) = '';
    local (@result) = ();
    if (length (@files))
    {
	# Turn sources into objects.
	foreach (@files)
	{
	    # Skip header files, including C++-ish ones.  The list
	    # of C++ header extensions comes from Emacs 19.32
	    # etags.
	    next if /\.[hH]$/;
	    next if /\.hxx$/;
	    next if /\.h\+\+$/;
	    next if /\.hh$/;
	    next if /\.hpp$/;
	    # Skip things that look like configure substitutions.
	    next if /^\@.*\@$/;

	    # Include .c file for lex or yacc source in distribution.
	    if (/^(.*)\.y$/)
	    {
		# Yacc source.
		&push_dist_common ($1 . '.c');
		$yacc_sources{$_} = 1;
	    }
	    elsif (/^(.*)\.l$/)
	    {
		# Lex source.
		&push_dist_common ($1 . '.c');
		$lex_sources{$_} = 1;
	    }

	    # Transform source files into .o files.  List of C++
	    # extensions comes from Emacs 19.34 etags.
	    if (s/\.(c\+\+|cc|cpp|cxx|C)$/o/)
	    {
		$cxx_extensions{'.' . $1} = 1;
		$linker = 'CXXLINK';
	    }
	    elsif (s/\.([Ff]\\|f90\\|for)$/o/)
	    {
		# FORTRAN support.  FIXME: not finished.
	    }
	    else
	    {
		# C, yacc, and lex need special $obj extension, for
		# de-ansification.  Hopefully someday this will go
		# away.
		s/\.[cly]$/$obj/g;

		# .s is assembly.  .M is Objective-C++.  .m is
		# Objective-C.
		s/\.[smM]$/$obj/g;

		# FIXME: of course, this should only happen for C
		# source.  The multi-language support must really be
		# cleaned up more globally.
		$seen_c_source = 1;
	    }

	    push (@result, $_);

	    # Transform .o or $o file into .P file (for automatic
	    # dependency code).
	    s/$objpat$/.P/g;
	    $dep_files{'.deps/' . $_} = 1;
	}
    }

    return ($linker, @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.
    local ($one_file, $unxformed, $obj) = @_;
    local ($objpat) = $obj;
    $objpat =~ s/(\W)/\\$1/g;
    # Handle explicit `.o' as well as whatever we're passed.
    $objpat = '(' . $objpat . "|\\.o)";

    local ($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;
    }

    local (@files, @result, $prefix, $temp);
    foreach $prefix ('', 'EXTRA_')
    {
	@files = ();
	if (&variable_defined ($prefix . $one_file . "_SOURCES"))
	{
	    push (@sources, '$(' . $prefix . $one_file . "_SOURCES)");
	    push (@objects, '$(' . $prefix . $one_file . "_OBJECTS)")
		unless $prefix eq 'EXTRA_';
	    @files = &variable_value_as_list ($prefix
					      . $one_file . "_SOURCES");
	}
	elsif ($prefix eq '')
	{
	    &define_variable ($one_file . "_SOURCES", $unxformed . ".c");
	    push (@sources, $unxformed . '.c');
	    push (@objects, $unxformed . $obj);
	    push (@files, $unxformed . '.c');
	}
	else
	{
	    &define_variable ("EXTRA_" . $one_file . "_SOURCES", '');
	}

	($temp, @result) = &handle_single_transform_list (@files);
	$linker = $temp if $linker eq '';
	&define_pretty_variable ($one_file . "_OBJECTS", @result)
	    unless $prefix eq 'EXTRA_';
    }

    if (&variable_defined ('CONFIG_HEADER'))
    {
	$output_rules .= ('$(' . $one_file . "_OBJECTS): "
			  . $contents{'CONFIG_HEADER'} . "\n");
    }

    return $linker;
}

# Handle the BUILT_SOURCES variable.
sub handle_built_sources
{
    return unless &variable_defined ('BUILT_SOURCES');
    push (@all, '$(BUILT_SOURCES)');

    local (@sources) = &variable_value_as_list ('BUILT_SOURCES');
    local ($s);
    foreach $s (@sources)
    {
	if (/^\@.*\@$/)
	{
	    # FIXME: is this really the right thing to do?
	    &am_line_error ('BUILT_SOURCES', "\`BUILT_SOURCES' should not contain a configure substitution");
	    last;
	}
    }

    # We don't care about the return value of this function.  We just
    # want to make sure to update %dep_files with the contents of
    # BUILT_SOURCES.
    &handle_single_transform_list (@sources);
}

# 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.  If set, LEXLIB
#     must be in LDADD.
# Returns 1 if LIBOBJS seen, 0 otherwise.
sub handle_lib_objects
{
    local ($xname, $var, $lex_seen) = @_;

    die "programming error 1 in handle_lib_objects"
	if ! &variable_defined ($var);

    die "programming error 2 in handle_lib_objects"
	if $lex_seen && $var =~ /LIBADD/;

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

    # If no lex source seen, just assume this is ok.
    local ($lex_ok) = $lex_seen ? 0 : 1;

    local ($seen_libobjs) = 0;

    foreach $lsearch (&variable_value_as_list ($var))
    {
	# Skip -lfoo and -Ldir.
	next if $lsearch =~ /^-[lL]/;

	# 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.
	push (@dep_list, $lsearch)
	    unless $lsearch =~ /^\@.*\@$/;

	# Automatically handle @LIBOBJS@ and @ALLOCA@.  Basically this
	# means adding entries to dep_files.
	if ($lsearch eq '@LIBOBJS@')
	{
	    $seen_libobjs = 1;
	    if (! keys %libsources)
	    {
		&am_line_error ($var, "\@LIBOBJS\@ seen but never set in \`configure.in'");
	    }

	    local ($iter, $rewrite);
	    foreach $iter (keys %libsources)
	    {
		if ($iter =~ /\.h$/)
		{
		    &require_file_with_line ($var, $FOREIGN, $iter);
		}
		elsif ($iter ne 'alloca.c')
		{
		    ($rewrite = $iter) =~ s/\.c$/.P/;
		    $dep_files{'.deps/' . $rewrite} = 1;
		    &require_file_with_line ($var, $FOREIGN, $iter);
		}
	    }
	}
	elsif ($lsearch eq '@ALLOCA@')
	{
	    &am_line_error ($var,
			    "\@ALLOCA\@ seen but \`AC_FUNC_ALLOCA' not in \`configure.in'")
		if ! defined $libsources{'alloca.c'};
	    $dep_files{'.deps/alloca.P'} = 1;
	    &require_file_with_line ($var, $FOREIGN, 'alloca.c');
	}
	elsif ($lsearch eq '@LEXLIB@')
	{
	    # FIXME: variable_value_as_list requires us to force
	    # @LEXLIB@ here, where we're really prefer $(LEXLIB).
	    # Nasty -- this will have to wait until many cleanups are
	    # made, I think.
	    $lex_ok = 1;
	}

    }

    if (! $lex_ok)
    {
	&am_line_error ($var, 'lex source file used without @LEXLIB@');
    }

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

    return $seen_libobjs;
}

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

    # If a program is installed, this is required.  We only want this
    # error to appear once.
    &am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	unless $seen_arg_prog;
    $seen_arg_prog = 1;

    local ($obj) = &get_object_extension;
    local ($one_file, $xname, $munge);

    local ($seen_libobjs) = 0;
    foreach $one_file (@proglist)
    {
	# Canonicalize names.
	($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;
	if ($xname ne $one_file)
	{
	    local ($xt);
	    foreach $xt ('_LDADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
	    {
		&am_line_error ($one_file . $xt,
				"invalid variable \`" . $one_file . $xt
				. "'; should be \`" . $xname . $xt . "'")
		    if &variable_defined ($one_file . $xt);
	    }
	}

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

	if (&variable_defined ($xname . "_LDADD"))
	{
	    if (&handle_lib_objects ($xname, $xname . '_LDADD',
				     $lex_file_seen))
	    {
		$seen_libobjs = 1;
	    }
	    $lex_file_seen = 0;
	}
	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;
	    }
	}

	if ($lex_file_seen)
	{
	    &am_line_error ($one_file . $xt,
			    'lex source file used without @LEXLIB@');
	}

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

	$output_rules .=
	    &file_contents_with_transform
		('s/\@PROGRAM\@/' . $one_file . '/go;'
		 . 's/\@XPROGRAM\@/' . $xname . '/go;'
		 . 's/\@XLINK\@/' . $xlink . '/go;',
		 'program');
    }

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

    if ($seen_libobjs)
    {
	foreach $one_file (@proglist)
	{
	    # Canonicalize names.
	    ($xname = $one_file) =~ tr/A-Za-z0-9_/_/c;

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

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

    local (%valid) = &am_primary_prefixes ('LIBRARIES', 'lib', 'pkglib',
					   'noinst', 'check');
    if (! defined $configure_vars{'RANLIB'})
    {
	local ($key);
	foreach $key (keys %valid)
	{
	    if (&variable_defined ($key . '_LIBRARIES'))
	    {
		&am_line_error ($key . '_LIBRARIES', "library used but \`RANLIB' not defined in \`configure.in'");
		# Only get this error once.
		$configure_vars{'RANLIB'} = 1;
		last;
	    }
	}
    }

    # Generate _LIBFILES variables.  Too bad we can't do this in
    # am_install_var.
    local ($onedir, $onelib);
    local (@outlist);
    local (@libfiles_list);
    foreach $onedir (keys %valid) 
    {
	if (&variable_defined ($onedir . '_LIBRARIES'))
	{
	    @outlist = ();
	    foreach $onelib (&variable_value_as_list ($onedir . '_LIBRARIES'))
	    {
		# FIXME: configure substitutions are just preserved.
		# So your configure.in must say MYLIB=libfoo.a instead
		# of MYLIB=foo.  Otherwise, you end up with an entry
		# like lib@MYLIB@.a in LIBFILES, which can turn into
		# "lib.a" -- major lossage.  Something better must be
		# done here.
		if (/^\@.*\@$/)
		{
		    push (@outlist, $onelib);
		}
		else
		{
		    push (@outlist, 'lib' . $onelib . '.a');
		}
	    }
	    &define_pretty_variable ($onedir . '_LIBFILES', @outlist);
	}

	push (@libfiles_list, '$(' . $onedir . '_LIBFILES)')
	    unless $onedir eq 'EXTRA';
    }
    push (@all, '$(LIBFILES)');

    local ($obj) = &get_object_extension;
    local ($munge);
    local ($xlib);
    local ($seen_libobjs) = 0;
    foreach $onelib (@liblist)
    {
	# Canonicalize names.
	($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	if ($xlib ne $onelib)
	{
	    local ($xt);
	    foreach $xt ('_LIBADD', '_SOURCES', '_OBJECTS', '_DEPENDENCIES')
	    {
		&am_line_error ($one_file . $xt,
				"invalid variable \`" . $onelib . $xt
				. "'; should be \`" . $xlib . $xt . "'")
		    if &variable_defined ($onelib . $xt);
	    }
	}

	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", '');
	}

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

	$output_rules .=
	    &file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
					   . 's/\@XLIBRARY\@/'
					   . $xlib . '/go;',
					   'library');
    }

    if ($seen_libobjs)
    {
	foreach $onelib (@liblist)
	{
	    # Canonicalize names.
	    ($xlib = $onelib) =~ tr/A-Za-z0-9_/_/c;
	    if (&variable_defined ($xlib . '_LIBADD'))
	    {
		&check_libobjs_sources ($xlib, $xlib . '_LIBADD');
	    }
	}
    }

    # Turn "foo" into "libfoo.a" and include macro definition.
    grep (($_ = 'lib' . $_ . '.a') && 0, @liblist);

    if (! &variable_defined ('LIBFILES'))
    {
	&define_pretty_variable ('LIBFILES ', @libfiles_list);
    }

    &define_variable ('AR', 'ar');
    &define_configure_variable ('RANLIB');
}

# See if any _SOURCES variable were misspelled.
sub check_typos
{
    local ($varname, $primary);
    foreach $varname (keys %contents)
    {
	foreach $primary ('_SOURCES', '_LIBADD', '_LDADD', '_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 ('scripts', 'SCRIPTS',
		     'bin', 'sbin', 'libexec', 'pkgdata',
		     'noinst', 'check');

    # 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.
    local (%valid) = &am_primary_prefixes ('SCRIPTS', 'bin', 'sbin',
					   'libexec', 'pkgdata',
					   'noinst', 'check');
    local ($key);
    foreach $key (keys %valid)
    {
	if ($key ne 'noinst'
	    && $key ne 'check'
	    && &variable_defined ($key . '_SCRIPTS'))
	{
	    $scripts_installed = 1;
	    # push (@check, 'check-' . $key . 'SCRIPTS');
	}
    }

    if ($scripts_installed)
    {
	# If a program is installed, this is required.  We only want this
	# error to appear once.
	&am_conf_error ("AC_ARG_PROGRAM must be used in configure.in")
	    unless $seen_arg_prog;
	$seen_arg_prog = 1;
    }
}

# Search a file for a "version.texi" Texinfo include.  Return the name
# of the include file if found, or the empty string if not.  A
# "version.texi" file is actually any file whose name matches
# "vers*.texi".
sub grep_for_vers_texi
{
    local ($filename) = @_;

    if (! open (TEXI, $filename))
    {
	&am_error ("couldn't open \`$filename': $!");
	return '';
    }
    print "automake: reading $filename\n" if $verbose;

    while (<TEXI>)
    {
	if (/^\@include\s+(vers[^.]*\.texi)\s*$/)
	{
	    # Found it.
	    close (TEXI);
	    return $1;
	}
    }

    close (TEXI);
    return '';
}

# 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'));

    local (@texis) = &variable_value_as_list ('info_TEXINFOS');

    local (@info_deps_list, @dvis_list, @texi_deps);
    local ($infobase, $info_cursor);
    local (%versions);
    local ($done) = 0;
    local ($vti);
    local ($tc_cursor, @texi_cleans);
    local ($canonical);

    foreach $info_cursor (@texis)
    {
	($infobase = $info_cursor) =~ s/\.texi(nfo)?$//;

	# If 'version.texi' is referenced by input file, then include
	# automatic versioning capability.
	local ($vtexi)
	    = &grep_for_vers_texi ($relative_dir . "/" . $info_cursor);
	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.
	    $vti = 'vti' . ($done ? $done : '');
	    &push_dist_common ($vtexi, 'stamp-' . $vti);
	    push (@clean, $vti);

	    # Only require once.
	    &require_conf_file_with_line ('info_TEXINFOS', $FOREIGN,
					  'mdate-sh')
		if ! $done;
	    ++$done;

	    local ($conf_pat);
	    ($conf_pat = $config_aux_dir) =~ s/(\W)/\\$1/g;
	    $output_rules .=
		&file_contents_with_transform
		    ('s/\@TEXI\@/' . $info_cursor . '/g; '
		     . 's/\@VTI\@/' . $vti . '/g; '
		     . 's/\@VTEXI\@/' . $vtexi . '/g;'
		     . 's,\@MDDIR\@,' . $conf_pat . ',g;',
		     'texi-vers');

	    &push_phony_cleaners ($vti);
	}

	# If user specified file_TEXINFOS, then use that as explicit
	# dependency list.
	@texi_deps = ();
	push (@texi_deps, $info_cursor);
	push (@texi_deps, $vtexi) if $vtexi;

	# Canonicalize name first.
	($canonical = $infobase) =~ tr/A-Za-z0-9_/_/c;
	if (&variable_defined ($canonical . "_TEXINFOS"))
	{
	    push (@texi_deps, '$(' . $canonical . '_TEXINFOS)');
	    &push_dist_common ('$(' . $canonical . '_TEXINFOS)');
	}

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

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

	# Generate list of things to clean for this target.  We do
	# this explicitly because otherwise too many things could be
	# removed.  In particular the ".log" extension might
	# reasonably be used in other contexts by the user.
	foreach $tc_cursor ('aux', 'cp', 'cps', 'dvi', 'fn', 'fns',
			    'ky', 'log', 'pg', 'toc', 'tp', 'vr', 'op')
	{
	    push (@texi_cleans, $infobase . '.' . $tc_cursor);
	}
    }

    # Find these programs wherever they may lie.  Yes, this has
    # intimate knowledge of the structure of the texinfo distribution.
    &define_program_variable ('MAKEINFO', 'build', 'texinfo/makeinfo',
			      'makeinfo');
    &define_program_variable ('TEXI2DVI', 'src', 'texinfo/util',
			      'texi2dvi');

    local ($xform);
    if ($cygnus_mode)
    {
	$xform = 'next if /^NOTCYGNUS/; s/^CYGNUS//;';
    }
    else
    {
	$xform = 'next if /^CYGNUS/; s/^NOTCYGNUS//;';
    }
    $output_rules .= &file_contents_with_transform ($xform, 'texinfos');
    push (@phony, 'install-info-am', 'uninstall-info');
    push (@dist_targets, 'dist-info');

    # How to clean.
    $output_rules .= "\nmostlyclean-info:\n";
    &pretty_print_rule ("\trm -f", "\t  ", @texi_cleans);
    $output_rules .= ("\nclean-info:\n\ndistclean-info:\n\n"
		      . "maintainer-clean-info:\n\t"
		      . 'for i in $(INFO_DEPS); do rm `eval echo $i*`; done'
		      . "\n");
    &push_phony_cleaners ('info');

    push (@suffixes, '.texi', '.texinfo', '.info', '.dvi');

    if (! defined $options{'no-installinfo'})
    {
	push (@uninstall, 'uninstall-info');
	push (@installdirs, '$(infodir)');
	unshift (@install_data, 'install-info-am');

	# 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)');
    }
    push (@clean, 'info');
    push (@info, '$(INFO_DEPS)');
    push (@dvi, '$(DVIS)');

    &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", $contents{'info_TEXINFOS'});

    # Do some error checking.  Note that this file is not required
    # when in Cygnus mode -- a bletcherous hack.
    &require_file_with_line ('info_TEXINFOS',
			     $cygnus_mode ? $GNU : $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');
    return if ! &variable_defined ('man_MANS');

    # We generate the manpage install code by hand to avoid the use of
    # basename in the generated Makefile.
    local (@mans) = &variable_value_as_list ('man_MANS');
    local (%sections, %inames, %mbases, %secmap, %fullsecmap);
    local ($i) = 1;
    foreach (@mans)
    {
	# FIXME: statement without effect:
	/^(.*)\.([0-9])([a-z]*)$/;
	$sections{$2} = 1;
	$inames{$i} = $_;
	$mbases{$i} = $1;
	$secmap{$i} = $2;
	$fullsecmap{$i} = $2 . $3;
	$i++;
    }

    # We don't really need this, but we use it in case we ever want to
    # support noinst_MANS.
    &define_variable ("MANS", $contents{'man_MANS'});

    # Generate list of install dirs.
    $output_rules .= "install-man: \$(MANS)\n";
    $output_rules .= "\t\$(NORMAL_INSTALL)\n";
    foreach (keys %sections)
    {
	push (@installdirs, '$(mandir)/man' . $_)
	    unless defined $options{'no-installman'};
	$output_rules .= ("\t" . '$(mkinstalldirs) $(mandir)/man'
			  . $_ . "\n");
    }
    push (@phony, 'install-man');

    # Generate install target.
    local ($key);
    foreach $key (keys %inames)
    {
	$_ = $install_man_format;
	s/\@SECTION\@/$secmap{$key}/g;
	s/\@MAN\@/$inames{$key}/g;
	s/\@FULLSECT\@/$fullsecmap{$key}/g;
	s/\@MANBASE\@/$mbases{$key}/g;
	$output_rules .= $_;
    }
    $output_rules .= "\n";

    $output_rules .= "uninstall-man:\n";
    foreach $key (keys %inames)
    {
	$_ = $uninstall_man_format;
	s/\@SECTION\@/$secmap{$key}/g;
	s/\@MAN\@/$inames{$key}/g;
	s/\@FULLSECT\@/$fullsecmap{$key}/g;
	s/\@MANBASE\@/$mbases{$key}/g;
	$output_rules .= $_;
    }
    $output_rules .= "\n";
    push (@phony, 'uninstall-man');

    $output_vars .= &file_contents ('mans-vars');

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

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

# Handle TAGS.
sub handle_tags
{
    local ($tagging) = 0;

    push (@phony, 'tags');
    if (&variable_defined ('SUBDIRS'))
    {
	$output_rules .= &file_contents ('tags');
	push (@phony, 'tags-recursive');
	$tagging = 1;
    }
    elsif ($dir_holds_sources
	   || $dir_holds_headers
	   || &variable_defined ('ETAGS_ARGS'))
    {
	$output_rules .= &file_contents ('tags-subd');
	$tagging = 1;
    }
    elsif (&variable_defined ('TAGS_DEPENDENCIES'))
    {
	&am_line_error ('TAGS_DEPENDENCIES',
			"doesn't make sense to define \`TAGS_DEPENDENCIES' without sources or \`ETAGS_ARGS'");
    }

    if ($tagging)
    {
	$output_rules .= &file_contents ('tags-clean');
	push (@clean, 'tags');
	&push_phony_cleaners ('tags');
	&examine_variable ('TAGS_DEPENDENCIES');
    }
    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";
    }
}

# Worker for handle_dist.
sub handle_dist_worker
{
    $output_rules .= 'distdir: $(DISTFILES)' . "\n";

    # Initialization; only at top level.
    if ($relative_dir eq '.')
    {
	if ($strictness >= $GNITS)
	{
	    # For Gnits users, this is pretty handy.  Look at 15 lines
	    # in case some explanatory text is desirable.
	    $output_rules .= '	@if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \\
	  echo "NEWS not updated; not releasing" 1>&2; \\
	  exit 1; \\
	fi
';
	}


	$output_rules .=
	    # Create dist directory.
	    '	rm -rf $(distdir)
	mkdir $(distdir)
	-chmod 755 $(distdir)
';

	# Only run automake in `dist' target if --include-deps not
	# specified.  That way the recipient of a distribution can run
	# "make dist" and not need Automake.
	if ($cmdline_use_dependencies)
	{
	    $output_rules .=
		(
		 # We need an absolute path for --output-dir.  Thus the
		 # weirdness.
		 '	here=`pwd`; distdir=`cd $(distdir) && pwd` \\
	  && cd $(srcdir) \\
	  && automake --include-deps --build-dir=$$here --srcdir-name=$(srcdir) --output-dir=$$distdir --strictness='
		 # Set strictness of output.
		 . $strictness_name
		 . ($cygnus_mode ? ' --cygnus' : '')
		 . "\n"
		 );
	}
    }

    # 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.
    local (@dist_dirs);
    if (&variable_defined ('EXTRA_DIST'))
    {
	foreach (&variable_value_as_list ('EXTRA_DIST'))
	{
	    next if /^\@.*\@$/;
	    next unless s,/+[^/]+$,,;
	    push (@dist_dirs, $_)
		unless $_ eq '.';
	}
    }
    if (&variable_defined ('EXTRA_DIST_DIRS'))
    {
	push (@dist_dirs, &variable_value_as_list ('EXTRA_DIST_DIRS'));
    }
    if (@dist_dirs)
    {
	# Prepend $(distdir) to each directory given.  Doing it via a
	# hash lets us ensure that each directory is used only once.
	local (%dhash);
	grep ($dhash{'$(distdir)/' . $_} = 1, @dist_dirs);
	$output_rules .= "\t";
	&pretty_print_rule ('$(mkinstalldirs)', "\t   ", sort keys %dhash);
    }

    # In loop, test for file existence because sometimes a file gets
    # included in DISTFILES twice.  For example this happens when a
    # single source file is used in building more than one program.
    # Also, there are situations in which "ln" can fail.  For instance
    # a file to distribute could actually be a cross-filesystem
    # symlink -- this can easily happen if "gettextize" was run on the
    # distribution.
    $output_rules .= "\t\@for file in \$(DISTFILES); do \\\n";
    if ($cygnus_mode)
    {
	$output_rules .= "\t  if test -f \$\$file; then d=.; else d=\$(srcdir); fi; \\\n";
    }
    else
    {
	$output_rules .= "\t  d=\$(srcdir); \\\n";
    }
    $output_rules .= '	  test -f $(distdir)/$$file \\
	  || ln $$d/$$file $(distdir)/$$file 2> /dev/null \\
	  || cp -p $$d/$$file $(distdir)/$$file; \\
	done
';

    # If we have SUBDIRS, create all dist subdirectories and do
    # recursive build.
    if (&variable_defined ('SUBDIRS'))
    {
	# Test for directory existence here because previous automake
	# invocation might have created some directories.  Note that
	# we explicitly set distdir for the subdir make; that lets us
	# mix-n-match many automake-using packages into one large
	# package, and have "dist" at the top level do the right
	# thing.
	$output_rules .= '	for subdir in $(SUBDIRS); do		\\
	  test -d $(distdir)/$$subdir		\\
	  || mkdir $(distdir)/$$subdir		\\
	  || exit 1;				\\
	  chmod 755 $(distdir)/$$subdir;	\\
	  (cd $$subdir && $(MAKE) distdir=../$(distdir)/$$subdir distdir) \\
	    || exit 1; \\
	done
';
    }

    # 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 defined $contents{'dist-hook'};

    local ($targ);
    foreach $targ (@dist_targets)
    {
	# We must explicitly set distdir for these sub-makes.
	$output_rules .= "\t\$(MAKE) distdir=\"\$(distdir)\" $targ\n";
    }

    push (@phony, 'distdir');
}

# Handle 'dist' target.
sub handle_dist
{
    # Set up maint_charset.
    $local_maint_charset = $contents{'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 = $contents{'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.
    local ($cfile);
    foreach $cfile (@common_files)
    {
	if (-f ($relative_dir . "/" . $cfile))
	{
	    &push_dist_common ($cfile);
	}
    }

    # Keys of %dist_common are names of files to distributed.  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.
    local (@coms);
    if (defined $dist_common{'README'})
    {
	push (@coms, 'README');
	undef $dist_common{'README'};
    }
    push (@coms, sort keys %dist_common);

    &define_pretty_variable ("DIST_COMMON", @coms);
    $output_vars .= "\n";

    # Some boilerplate.
    $output_vars .= &file_contents ('dist-vars');

    # Put these things in rules section so it is easier for whoever
    # reads Makefile.in.
    if (! &variable_defined ('distdir'))
    {
	if ($relative_dir eq '.')
	{
	    $output_rules .= "\n" . 'distdir = $(PACKAGE)-$(VERSION)' . "\n";
	}
	else
	{
	    $output_rules .= ("\n"
			      . 'distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)'
			      . "\n");
	}
    }
    if ($relative_dir ne '.')
    {
	$output_rules .= "\nsubdir = " . $relative_dir . "\n";
    }

    # Generate 'dist' target, and maybe dist-shar / dist-zip / dist-tarZ.
    if ($relative_dir eq '.')
    {
	# Rule to check whether a distribution is viable.
	$output_rules .= ('# This target untars the dist file and tries a VPATH configuration.  Then
# it guarantees that the distribution is self-contained by making another
# tarfile.
distcheck: dist
	rm -rf $(distdir)
	$(TAR) zxf $(distdir).tar.gz
	mkdir $(distdir)/=build
	mkdir $(distdir)/=inst
	dc_install_base=`cd $(distdir)/=inst && pwd`; \\'
			  . (defined $contents{'distcheck-hook'}
			     ? "\t\$(MAKE) distcheck-hook"
			     : '')
			  . '
	cd $(distdir)/=build \\
	  && ../configure '

			  . ($seen_gettext ? '--with-included-gettext ' : '')
			  . '--srcdir=.. --prefix=$$dc_install_base \\
	  && $(MAKE) \\
	  && $(MAKE) dvi \\
	  && $(MAKE) check \\
	  && $(MAKE) install \\
	  && $(MAKE) installcheck \\
	  && $(MAKE) dist
	rm -rf $(distdir)
	@echo "========================"; \\
	echo "$(distdir).tar.gz is ready for distribution"; \\
	echo "========================"
');

	local ($dist_all) = ('dist-all: distdir' . "\n"
			     . $dist_header);
	local ($curs);
	foreach $curs ('dist', 'dist-shar', 'dist-zip', 'dist-tarZ')
	{
	    if (defined $options{$curs} || $curs eq 'dist')
	    {
		$output_rules .= ($curs . ': distdir' . "\n"
				  . $dist_header
				  . $dist{$curs}
				  . $dist_trailer);
		$dist_all .= $dist{$curs};
	    }
	}
	$output_rules .= $dist_all . $dist_trailer;
    }

    # Generate distdir target.
    &handle_dist_worker;
}

# Scan a single dependency file and rewrite the dependencies as
# appropriate.  Essentially this means:
# * Clean out absolute dependencies which are not desirable.
# * Rewrite other dependencies to be relative to $(top_srcdir).
sub scan_dependency_file
{
    local ($depfile) = @_;

    if (! open (DEP_FILE, $depfile))
    {
	&am_error ("couldn't open \`$depfile': $!");
	return;
    }
    print "automake: reading $depfile\n" if $verbose;

    # Sometimes it is necessary to omit some dependencies.
    local (%omit) = %omit_dependencies;
    if (&variable_defined ('OMIT_DEPENDENCIES'))
    {
	grep ($omit{$_} = 1, &variable_value_as_list ('OMIT_DEPENDENCIES'));
    }

    local ($first_line) = 1;
    local ($last_line) = 0;
    local ($target, @dependencies);
    local ($one_dep, $xform);
    local ($just_file);

    local ($srcdir_rx, $fixup_rx);
    # If the top srcdir is absolute, then the current directory is
    # just relative_dir.  But if the top srcdir is relative, then we
    # need to add some dots first.  The same holds when matching
    # srcdir directly.
    if ($srcdir_name =~ /^\//)
    {
	($fixup_rx = $srcdir_name . '/' . $relative_dir . '/')
	    =~ s/(\W)/\\$1/g;
	($srcdir_rx = $srcdir_name) =~ s/(\W)/\\$1/g;
    }
    else
    {
	($fixup_rx = ($srcdir_name . '/' . $top_builddir . '/'
		      . $relative_dir . '/')) =~ s/(\W)/\\$1/g;
	($srcdir_rx = ($srcdir_name . '/' . $top_builddir))
	    =~ s/(\W)/\\$1/g;
    }

    while (<DEP_FILE>)
    {
	if ($last_line)
	{
	    # If LAST_LINE set then we've already seen what we thought
	    # was the last line.
	    goto bad_format;
	}
	next if (/$WHITE_PATTERN/o);
	chop;
	if (! s/\\$//)
	{
	    # No trailing "\" means this should be the last line.
	    $last_line = 1;
	}

	if ($first_line)
	{
	    if (! /^([^:]+:)(.+)$/)
	    {
	      bad_format:
		&am_error ("\`$depfile' has incorrect format");
		close (DEP_FILE);
		return;
	    }

	    $target = $1;
	    $_ = $2;

	    $first_line = 0;
	}

	foreach $one_dep (split (' ', $_))
	{
	    if ($one_dep =~ /^$fixup_rx/)
	    {
		# The dependency points to the current directory in
		# some way.
		($xform = $one_dep) =~ s/^$fixup_rx//;
		push (@dependencies, $xform);
	    }
	    elsif ($one_dep =~ /^$srcdir_rx\//)
	    {
		# The dependency is in some other directory in the package.
		($xform = $one_dep) =~ s/^$srcdir_rx/$top_builddir/;
		push (@dependencies, $xform);
	    }
	    elsif ($one_dep =~ /^\//)
	    {
		# Absolute path; ignore.
	    }
	    else
	    {
		# Anything else is assumed to be correct.  But first
		# make sure it is not on our list of dependencies to
		# omit.
		($just_file = $one_dep) =~ s,^.*/,,;
		push (@dependencies, $one_dep)
		    if ! defined $omit{$just_file};
	    }
	}
    }

    &pretty_print_rule ($target, "\t", @dependencies);

    close (DEP_FILE);
}

# Handle auto-dependency code.
sub handle_dependencies
{
    if ($use_dependencies)
    {
	# Include GNU-make-specific auto-dep code.
	if ($dir_holds_sources)
	{
	    &define_pretty_variable ('DEP_FILES', sort keys %dep_files);
	    $output_rules .= &file_contents ('depend');
	    push (@clean, 'depend');
	    &push_phony_cleaners ('depend');
	    $output_rules .=
		&file_contents_with_transform ('s/\@EXT\@/.c/g;'
					       . 's/\@MKDEP\@/MKDEP/g',
					       'depend2');
	    local ($ext);
	    local ($need_cxx) = 0;
	    foreach $ext (keys %cxx_extensions)
	    {
		$output_rules .=
		    &file_contents_with_transform ('s/\@EXT\@/' . $ext .'/g;'
						   . 's/\@MKDEP\@/CXXMKDEP/g',
						   'depend2');
		$need_cxx = 1;
	    }
	    if ($need_cxx)
	    {
		&define_variable ('CXXMKDEP', '$(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)');
	    }
	}
    }
    else
    {
	# FIXME: consider requiring --build-dir here.  What about case
	# where this is done via an option?

	# Include any auto-generated deps that are present.  Note that
	# $build_directory ends in a "/".
	if (-d ($build_directory . $relative_dir . "/.deps")
	    && -f ($build_directory . $relative_dir . "/.deps/.P"))
	{
	    local ($depfile);
	    local ($gpat) = $build_directory . $relative_dir . "/.deps/*.P";

	    foreach $depfile (<${gpat}>)
	    {
		&scan_dependency_file ($depfile);
	    }

	    $output_rules .= "\n";
	}
    }
}

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

    # Make sure each directory mentioned in SUBDIRS actually exists.
    local ($dir);
    foreach $dir (&variable_value_as_list ('SUBDIRS'))
    {
	# Skip directories substituted by configure.
	next if $dir =~ /^\@.*\@$/;
	&am_line_error ('SUBDIRS',
			"required directory $relative_dir/$dir does not exist")
	    if ! -d $relative_dir . '/' . $dir;
    }

    local ($xform) = ('s/\@INSTALLINFO\@/' .
		      (defined $options{'no-installinfo'}
		       ? 'install-info-recursive'
		       : '')
		      . '/;');
    $output_rules .= &file_contents_with_transform ($xform, 'subdirs');

    # Push a bunch of phony targets.
    local ($phonies);
    foreach $phonies ('-data', '-exec', 'dirs')
    {
	push (@phony, 'install' . $phonies . '-recursive');
	push (@phony, 'uninstall' . $phonies . '-recursive');
    }
    foreach $phonies ('all', 'check', 'installcheck', 'info', 'dvi')
    {
	push (@phony, $phonies . '-recursive');
    }
    &push_phony_cleaners ('recursive');

    push (@check, "check-recursive");
    push (@installcheck, "installcheck-recursive");
    push (@info, "info-recursive");
    push (@dvi, "dvi-recursive");

    $recursive_install = 1;
}

# Handle aclocal.m4.
sub handle_aclocal_m4
{
    local ($regen_aclocal) = 0;
    if (-f 'aclocal.m4')
    {
	&define_variable ("ACLOCAL", '$(top_srcdir)/aclocal.m4');
	&push_dist_common ('aclocal.m4');

	if (open (ACLOCAL, '< aclocal.m4'))
	{
	    local ($line);
	    $line = <ACLOCAL>;
	    close (ACLOCAL);

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

    local ($acinclude) = 0;
    if (-f 'acinclude.m4')
    {
	$regen_aclocal = 1;
	$acinclude = 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.
    if ($regen_aclocal)
    {
	$output_rules .= ("\$(srcdir)/aclocal.m4: "
			  . ($seen_maint_mode ? "\@MAINT\@" : "")
			  . "configure.in"
			  . ($acinclude ? ' acinclude.m4' : '')
			  . "\n\t"
			  . 'cd $(srcdir) && aclocal'
			  . "\n");
    }
}

# Handle remaking and configure stuff.
sub handle_configure
{
    # If SUBDIRS defined, require AC_PROG_MAKE_SET.
    &am_line_error ('SUBDIRS', "AC_PROG_MAKE_SET must be used in configure.in")
	if &variable_defined ('SUBDIRS') && ! $seen_make_set;

    local ($top_reldir);
    local ($xform) = ('s/\@ARGS\@/--strictness=' . $strictness_name
		      . ($cygnus_mode ? ' --cygnus' : '')
		      . '/;');
    if ($relative_dir ne '.')
    {
	# In subdirectory.
	$output_rules .= &file_contents_with_transform ($xform, 'remake-subd');
	$top_reldir = '../';
    }
    else
    {
	&handle_aclocal_m4;
	$output_rules .= &file_contents_with_transform ($xform, 'remake');
	&examine_variable ('CONFIGURE_DEPENDENCIES');
	$top_reldir = '';
    }

    # If we have a configure header, require it.
    if ($config_header && $relative_dir eq &dirname ($config_header))
    {
	local ($ch_sans_dir) = &basename ($config_header);
	local ($cn_sans_dir) = &basename ($config_name);

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

	# Header defined and in this directory.
	local (@files);
	if (-f $relative_dir . '/acconfig.h')
	{
	    push (@files, 'acconfig.h');
	}
	if (-f $config_name . '.top')
	{
	    push (@files, "${cn_sans_dir}.top");
	}
	if (-f $config_name . '.bot')
	{
	    push (@files, "${cn_sans_dir}.bot");
	}

	&push_dist_common (@files);
	$output_rules .= &file_contents_with_transform ('s/\@FILES\@/'
							. join (' ', @files)
							. '/;',
							'remake-hdr');

	&touch ($relative_dir . '/stamp-h.in');
	&require_file_with_conf_line ($config_header_line, $FOREIGN,
				      'stamp-h.in');

	push (@clean, 'hdr');
	&push_phony_cleaners ('hdr');
	&define_variable ("CONFIG_HEADER_IN", "${ch_sans_dir}");
    }

    # 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.in'")
	if &variable_defined ('CONFIG_HEADER');

    if ($config_name)
    {
	# Generate CONFIG_HEADER define.
	if ($relative_dir eq &dirname ($config_name))
	{
	    &define_variable ("CONFIG_HEADER", &basename ($config_name));
	}
	else
	{
	    &define_variable ("CONFIG_HEADER",
			      "${top_builddir}/${config_name}");
	}
    }

    # Now look for other files in this directory which must be remade
    # by config.status, and generate rules for them.
    local (@actual_other_files) = ();
    local ($file, $local, $input);
    foreach $file (@other_input_files)
    {
	# Skip files not in this directory, any Makefile, and the
	# config header.  These last two must be handled specially.
	next unless &dirname ($file) eq $relative_dir;
	next if $file eq $top_builddir . '/' . $config_name;
	($local = $file) =~ s/^.*\///;
	next if $local eq 'Makefile';

	if ($local =~ /^(.*):(.*)$/)
	{
	    # This is the ":" syntax of AC_OUTPUT.
	    $input = $2;
	    $local = $1;
	}
	else
	{
	    # Normal usage.
	    $input = $local . '.in';
	}
	# FIXME: when using autoconf ":" syntax, should we set CONFIG_FILES
	# to $local:$input?
	$output_rules .= ($local . ': '
			  . '$(top_builddir)/config.status ' . $input . "\n"
			  . "\t"
			  . 'cd $(top_builddir) && CONFIG_FILES='
			  . ($relative_dir eq '.' ? '' : '$(subdir)/')
			  . '$@ CONFIG_HEADERS= ./config.status'
			  . "\n");
	push (@actual_other_files, $local);

	&require_file_with_conf_line ($ac_output_line, $FOREIGN,
				      $input);
    }

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

# Handle C headers.
sub handle_headers
{
    $dir_holds_headers = &am_install_var ('header', 'HEADERS', 'include',
					  'oldinclude', 'pkginclude',
					  'noinst', 'check');
}

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

    if (! &variable_defined ('SUBDIRS'))
    {
	&am_conf_error
	    ("ud_GNU_GETTEXT in configure.in but SUBDIRS not defined");
	return;
    }

    &require_file_with_conf_line ($ac_gettext_line, $FOREIGN, 'ABOUT-NLS')
	if $seen_gettext;

    if (&variable_defined ('SUBDIRS'))
    {
	&am_line_error
	    ('SUBDIRS',
	     "ud_GNU_GETTEXT in configure.in but \`po' not in SUBDIRS")
		if $contents{'SUBDIRS'} !~ /\bpo\b/;
	&am_line_error
	    ('SUBDIRS',
	     "ud_GNU_GETTEXT in configure.in but \`intl' not in SUBDIRS")
		if $contents{'SUBDIRS'} !~ /\bintl\b/;
    }

    # Ensure that each language in ALL_LINGUAS has a .po file, and
    # each po file is mentioned in ALL_LINGUAS.
    if ($seen_linguas)
    {
	local (%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 ("ud_GNU_GETTEXT in configure.in but \`ALL_LINGUAS' not defined");
    }
}

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

    if (defined $contents{'SUFFIXES'})
    {
	# Push actual suffixes, and not $(SUFFIXES).  Some versions of
	# make do not like variable substitutions on the .SUFFIXES
	# line.
	push (@suffixes, split (' ', $contents{'SUFFIXES'}));
    }

    $output_trailer .= ".SUFFIXES:\n";
    if (@suffixes)
    {
	$output_trailer .= ".SUFFIXES: " . join (' ', @suffixes) . "\n";
    }
    $output_trailer .= &file_contents ('footer');
}

# Deal with installdirs target.
sub handle_installdirs
{
    # GNU Makefile standards recommend this.
    $output_rules .= ("installdirs:"
		      . ($recursive_install
			 ? " installdirs-recursive\n"
			 : "\n"));
    push (@phony, 'installdirs');
    if (@installdirs)
    {
	&pretty_print_rule ("\t" . '$(mkinstalldirs) ', "\t\t",
			    @installdirs);
    }
    $output_rules .= "\n";
}

# There are several targets which need to be merged.  This is because
# their complete definition is compiled from many parts.  Note that we
# avoid double colon rules, otherwise we'd use them instead.
sub handle_merge_targets
{
    # There are a few install-related variables that you should not define.
    local ($var);
    foreach $var ('PRE_INSTALL', 'POST_INSTALL', 'NORMAL_INSTALL')
    {
	if (&variable_defined ($var))
	{
	    &am_line_error ($var, "\`$var' should not be defined");
	}
    }

    push (@all, 'Makefile');
    push (@all, $config_name)
	if $config_name && &dirname ($config_name) eq $relative_dir;

    &do_one_merge_target ('info', @info);
    &do_one_merge_target ('dvi', @dvi);
    &do_one_merge_target ('check', @check);
    &do_one_merge_target ('installcheck', @installcheck);

    if (defined $options{'no-installinfo'})
    {
	# FIXME: this is kind of a hack; should find another way to
	# know that this is required.
	local (@dirs);
	if (grep ($_ eq 'install-info-am', @phony))
	{
	    push (@dirs, 'install-info-am');
	}
	if (&variable_defined ('SUBDIRS'))
	{
	    push (@dirs, 'install-info-recursive');
	}
	&do_one_merge_target ('install-info', @dirs);
    }

    # Handle the various install targets specially.  We do this so
    # that (eg) "make install-exec" will run "install-exec-recursive"
    # if required, but "make install" won't run it twice.  Step one is
    # to see if the user specified local versions of any of the
    # targets we handle.  "all" is treated as one of these since
    # "install" can run it.
    push (@install_exec, 'install-exec-local')
	if defined $contents{'install-exec-local'};
    push (@install_data, 'install-data-local')
	if defined $contents{'install-data-local'};
    push (@uninstall, 'uninstall-local')
	if defined $contents{'uninstall-local'};
    local ($utarg);
    foreach $utarg ('uninstall-data-local', 'uninstall-data-hook',
		    'uninstall-exec-local', 'uninstall-exec-hook')
    {
	if (defined $contents{$utarg})
	{
	    local ($x);
	    ($x = $utarg) =~ s/(data|exec)-//;
	    &am_line_error ($utarg, "use \`$x', not \`$utarg'");
	}
    }
    push (@all, 'all-local')
	if defined $contents{'all-local'};

    if (defined $contents{'install-local'})
    {
	&am_line_error ('install-local',
			"use \`install-data' or \`install-exec', not \`install'");
    }

    # Step two: if we are doing recursive makes, write out the
    # appropriate rules.
    local (@install);
    if ($recursive_install)
    {
	push (@install, 'install-recursive');

	if (@all)
	{
	    local (@hackall) = ();
	    if ($config_name && &dirname ($config_name) eq $relative_dir)
	    {

		# This is kind of a hack, but I couldn't see a better
		# way to handle it.  In this particular case, we need
		# to make sure config.h is built before we recurse.
		# 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_rules .= ('all-recursive-hack: $(CONFIG_HEADER)'
				  . "\n\t" . '$(MAKE) all-recursive'
				  . "\n\n");
		push (@hackall, 'all-recursive-hack');
		push (@phony, 'all-recursive-hack');
	    }
	    else
	    {
		push (@hackall, 'all-recursive');
	    }

	    $output_rules .= ('all-am: '
			      . join (' ', @all)
			      . "\n\n");
	    @all = @hackall;
	    push (@all, 'all-am');
	    push (@phony, 'all-am');
	}
	else
	{
	    @all = ('all-recursive');

	    # Must always generate `all-am' target, so it can be
	    # referred to elsewhere.
	    $output_rules .= "all-am:\n";
	}
	if (@install_exec)
	{
	    $output_rules .= ('install-exec-am: '
			      . join (' ', @install_exec)
			      . "\n\n");
	    @install_exec = ('install-exec-recursive', 'install-exec-am');
	    push (@install, 'install-exec-am');
	    push (@phony, 'install-exec-am');
	}
	else
	{
	    @install_exec = ('install-exec-recursive');
	}
	if (@install_data)
	{
	    $output_rules .= ('install-data-am: '
			      . join (' ', @install_data)
			      . "\n\n");
	    @install_data = ('install-data-recursive', 'install-data-am');
	    push (@install, 'install-data-am');
	    push (@phony, 'install-data-am');
	}
	else
	{
	    @install_data = ('install-data-recursive');
	}
	if (@uninstall)
	{
	    $output_rules .= ('uninstall-am: '
			      . join (' ', @uninstall)
			      . "\n\n");
	    @uninstall = ('uninstall-recursive', 'uninstall-am');
	    push (@phony, 'uninstall-am');
	}
	else
	{
	    @uninstall = ('uninstall-recursive');
	}
    }

    # Step three: print definitions users can use.  Code below knows
    # that install-exec is done before install-data, beware.
    $output_rules .= ("install-exec: "
		      . join (' ', @install_exec)
		      . "\n");
    $output_rules .= "\t\$(NORMAL_INSTALL)\n";
    if (defined $contents{'install-exec-hook'})
    {
	$output_rules .= "\t" . '$(MAKE) install-exec-hook' . "\n";
    }
    $output_rules .= "\n";
    push (@install, 'install-exec') if !$recursive_install;
    push (@phony, 'install-exec');

    $output_rules .= ("install-data: "
		      . join (' ', @install_data)
		      . "\n");
    $output_rules .= "\t\$(NORMAL_INSTALL)\n";
    if (defined $contents{'install-data-hook'})
    {
	$output_rules .= "\t" . '$(MAKE) install-data-hook' . "\n";
    }
    $output_rules .= "\n";
    push (@install, 'install-data') if !$recursive_install;
    push (@phony, 'install-data');

    # If no dependencies for 'install', add 'all'.  Why?  That way
    # "make install" at top level of distclean'd distribution won't
    # fail because stuff in 'lib' fails to build.
    if (! @install || (scalar (@install) == 2
		       && $install[0] eq 'install-exec'
		       && $install[1] eq 'install-data'))
    {
	push (@install, 'all');
    }
    $output_rules .= ('install: '
		      . join (' ', @install)
		      # Use "@:" as empty command so nothing prints.
		      . "\n\t\@:"
		      . "\n\n"
		      . 'uninstall: '
		      . join (' ', @uninstall)
		      . "\n\n");
    push (@phony, 'install', 'uninstall');

    $output_rules .= ('all: '
		      . join (' ', @all)
		      . "\n\n");
    push (@phony, 'all');

    # Generate the new 'install-strip' target.
    $output_rules .= ("install-strip:\n\t"
		      . '$(MAKE) INSTALL_PROGRAM=\'$(INSTALL_PROGRAM) -s\' install'
		      . "\n");
}

# Helper for handle_merge_targets.
sub do_one_merge_target
{
    local ($name, @values) = @_;

    if (defined $contents{$name . '-local'})
    {
	# User defined local form of target.  So include it.
	push (@values, $name . '-local');
	push (@phony, $name . '-local');
    }

    local ($done) = 0;
    if ($name eq 'check')
    {
	if (! &variable_defined ('SUBDIRS'))
	{
	    # 'check' must depend on `all', but not when doing
	    # recursive build.
	    unshift (@values, 'all');
	}
	else
	{
	    # When subdirs are used, do the `all' build and then do
	    # all the recursive stuff.  Actually use `all-am' because
	    # it doesn't recurse; we rely on the check target in the
	    # subdirs to do the required builds there.
	    $output_rules .= "check: all-am\n";
	    &pretty_print_rule ("\t\$(MAKE)", "\t  ", @values);
	    $done = 1;
	}
    }

    &pretty_print_rule ($name . ":", "\t\t", @values)
	unless $done;
    push (@phony, $name);
}

# Handle all 'clean' targets.
sub handle_clean
{
    push (@clean, 'generic');
    $output_rules .= &file_contents ('clean');
    &push_phony_cleaners ('generic');

    local ($target) = $recursive_install ? 'clean-am' : 'clean';
    &do_one_clean_target ($target, 'mostly', '', @clean);
    &do_one_clean_target ($target, '', 'mostly', @clean);
    &do_one_clean_target ($target, 'dist', '', @clean);
    &do_one_clean_target ($target, 'maintainer-', 'dist', @clean);

    push (@phony, 'clean', 'mostlyclean', 'distclean', 'maintainer-clean');

    local (@deps);
    if ($recursive_install)
    {
	@deps = ('am', 'recursive');
	&do_one_clean_target ('', 'mostly', '', @deps);
	&do_one_clean_target ('', '', '', @deps);
	&do_one_clean_target ('', 'dist', '', @deps);
	&do_one_clean_target ('', 'maintainer-', '', @deps);
    }
}

# Helper for handle_clean.
sub do_one_clean_target
{
    local ($target, $name, $last_name, @deps) = @_;

    # Special case: if target not passed, then don't generate
    # dependency on next "lower" clean target (eg no
    # clean<-mostlyclean derivation).  In this case the target is
    # implicitly known to be 'clean'.
    local ($flag) = $target;
    $target = 'clean' if ! $flag;

    grep (($_ = $name . 'clean-' . $_) && 0, @deps);
    if ($flag)
    {
	if ($last_name || $name ne 'mostly')
	{
	    push (@deps, $last_name . $target . " ");
	}
    }
    # FIXME: not sure if I like the tabs here.
    &pretty_print_rule ($name . $target . ": ", "\t\t", @deps);

    # FIXME: shouldn't we really print these messages before running
    # the dependencies?
    if ($name . $target eq 'maintainer-clean')
    {
	# Print a special warning.
	$output_rules .=
	    ("\t\@echo \"This command is intended for maintainers to use;\"\n"
	     . "\t\@echo \"it deletes files that may require special "
	     . "tools to rebuild.\"\n");

	$output_rules .= "\trm -f config.status\n"
	    if $relative_dir eq '.';
    }
    elsif ($name . $target eq 'distclean')
    {
	$output_rules .= "\trm -f config.status\n";
	$output_rules .= "\trm -f libtool\n" if $seen_libtool;
    }
    $output_rules .= "\n";
}

# Handle .PHONY target.
sub handle_phony
{
    &pretty_print_rule ('.PHONY:', "", @phony);
    $output_rules .= "\n";
}

# Handle TESTS variable and other checks.
sub handle_tests
{
    if (defined $options{'dejagnu'})
    {
	push (@check, 'check-DEJAGNU');
	push (@phony, 'check-DEJAGNU');

	local ($xform);
	if ($cygnus_mode)
	{
	    $xform = 's/^CYGNUS//;';
	}
	else
	{
	    $xform = 'next if /^CYGNUS/;';
	}
	$output_rules .= &file_contents_with_transform ($xform, 'dejagnu');

	# In Cygnus mode, these are found in the build tree.
	# Otherwise they are looked for in $PATH.
	&define_program_variable ('EXPECT', 'build', 'expect', 'expect');
	&define_program_variable ('RUNTEST', 'src', 'dejagnu', 'runtest');

	# Note that in the rule we don't directly generate site.exp to
	# avoid the possibility of a corrupted site.exp if make is
	# interrupted.  Jim Meyering has some useful text on this
	# topic.
	$output_rules .= ("site.exp: Makefile\n"
			  . "\t\@echo 'Making a new site.exp file...'\n"
			  . "\t-\@rm -f site.bak\n"
			  . "\t\@echo '## these variables are automatically generated by make ##' > \$\@-t\n"
			  . "\t\@echo '# Do not edit here.  If you wish to override these values' >> \$\@-t\n"
			  . "\t\@echo '# edit the last section' >> \$\@-t\n"
			  . "\t\@echo 'set tool \$(DEJATOOL)' >> \$\@-t\n"
			  . "\t\@echo 'set srcdir \$(srcdir)' >> \$\@-t\n"
			  . "\t\@echo 'set objdir' \`pwd\` >> \$\@-t\n");

	# Extra stuff for AC_CANONICAL_*
	local (@whatlist) = ();
	if ($seen_canonical)
	{
	    push (@whatlist, 'host')
	}

	# Extra stuff only for AC_CANONICAL_SYSTEM.
	if ($seen_canonical == $AC_CANONICAL_SYSTEM)
	{
	    push (@whatlist, 'target', 'build');
	}

	local ($c1, $c2);
	foreach $c1 (@whatlist)
	{
	    foreach $c2 ('alias', 'triplet')
	    {
		$output_rules .= "\t\@echo 'set ${c1}_${c2} \$(${c1}_${c2})' >> \$\@-t\n";
	    }
	}

	$output_rules .= ("\t\@echo '## All variables above are generated by configure. Do Not Edit ##' >> \$\@-t\n"
			  . "\t-\@sed '1,/^## All variables above are.*##/ d' site.bak >> \$\@-t\n"
			  . "\t-\@mv site.exp site.bak\n"
			  . "\t\@mv \$\@-t site.exp\n");
    }
    else
    {
	local ($c);
	foreach $c ('DEJATOOL', 'RUNTEST', 'RUNTESTFLAGS')
	{
	    if (&variable_defined ($c))
	    {
		&am_line_error ($c, "\`$c' defined but \`dejagnu' not in \`AUTOMAKE_OPTIONS'");
	    }
	}
    }

    if (&variable_defined ('TESTS'))
    {
	push (@check, 'check-TESTS');
	push (@phony, 'check-TESTS');
	# FIXME: use $(SHELL) here?  That is what Ulrich suggests.
	# Maybe a new macro, $(TEST_SHELL), a la $(CONFIG_SHELL)?  For
	# now we just execute the file directly; this allows test
	# files which are compiled -- a possibly useful feature.
	$output_rules .= 'check-TESTS: $(TESTS)
	@failed=0; all=0; \\
	srcdir=$(srcdir); export srcdir; \\
	for tst in $(TESTS); do \\
	  all=`expr $$all + 1`; \\
	  if test -f $$tst; then dir=.; \\
	  else dir="$(srcdir)"; fi; \\
	  if $(TESTS_ENVIRONMENT) $$dir/$$tst; then \\
	    echo "PASS: $$tst"; \\
	  else \\
	    failed=`expr $$failed + 1`; \\
	    echo "FAIL: $$tst"; \\
	  fi; \\
	done; \\
	if test "$$failed" -eq 0; then \\
	  echo "========================"; \\
	  echo "All $$all tests passed"; \\
	  echo "========================"; \\
	else \\
	  echo "$$failed of $$all tests failed"; \\
	fi
';
    }
}

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

    if (@elfiles)
    {
	# Found some lisp.
	&define_configure_variable ('lispdir');
	&define_configure_variable ('EMACS');
	$output_rules .= (".el.elc:\n"
			  . "\t\@echo 'WARNING: Warnings can be ignored. :-)'\n"
			  . "\t\EMACS=$(EMACS) $(SHELL) \$(srcdir)/elisp-comp \$<\n");
	push (@suffixes, '.el', '.elc');

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

	push (@clean, 'lisp');
	&push_phony_cleaners ('lisp');

	local ($varname);
	if (&variable_defined ('lisp_LISP'))
	{
	    $varname = 'lisp_LISP';
	    &am_error ("\`lisp_LISP' defined but \`AM_PATH_LISPDIR' not in \`configure.in'")
		if ! $seen_lispdir;
	}
	else
	{
	    $varname = 'noinst_LISP';
	}

	&require_file_with_line ($varname, $FOREIGN, 'elisp-comp');
    }
}

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

# Scan configure.in for interesting things.
sub scan_configure
{
    open (CONFIGURE, 'configure.in')
	|| die "automake: couldn't open \`configure.in': $!\n";
    print "automake: reading configure.in\n" if $verbose;

    # Reinitialize libsources here.  This isn't really necessary,
    # since we currently assume there is only one configure.in.  But
    # that won't always be the case.
    %libsources = ();

    local ($in_ac_output, $in_ac_replace, @make_list) = (0, 0);
    local ($libobj_iter);
    while (<CONFIGURE>)
    {
	# Remove comments from current line.
	s/\bdnl\b.*$//;
	s/\#.*$//;

	# 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 (/AM_FUNC_FNMATCH/)
	{
	    $libsources{'fnmatch.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;
	    $omit_dependencies{'rx.h'} = 1;
	    $omit_dependencies{'regex.h'} = 1;
	}
	elsif (/AM_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 $libobj_iter (split (' ', $1))
	    {
		if ($libobj_iter =~ /^(.*)\.o$/)
		{
		    $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)
	    {
		$libsources{$_ . '.c'} = 1;
	    }
	}

	if (/(fp_WITH_DMALLOC|fp_WITH_REGEX|fp_FUNC_FNMATCH|fp_PROG_INSTALL|fp_C_PROTOTYPES|jm_MAINTAINER_MODE)/)
	{
	    &am_conf_line_error ($., "\`$1' is obsolete; use corresponding \`AM_' macro");
	}

	# Process the AC_OUTPUT macro.
	if (! $in_ac_output && s/AC_OUTPUT\s*\(\[?//)
	{
	    $in_ac_output = 1;
	    $ac_output_line = $.;
	}
	if ($in_ac_output)
	{
	    $in_ac_output = 0 if s/[\]\),].*$//;

	    # Look at potential Makefile.am's.
	    foreach (split)
	    {
		next if $_ eq "\\";
		if (-f $_ . '.am')
		{
		    push (@make_list, $_);
		}
		else
		{
		    push (@other_input_files, $_);
		}
	    }
	}

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

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

	# Check for NLS support.
	if (/ud_GNU_GETTEXT/)
	{
	    $seen_gettext = 1;
	    $ac_gettext_line = $.;
	    $omit_dependencies{'libintl.h'} = 1;
	}

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

	# Handle configuration headers.
	if (/AC_CONFIG_HEADER\s*\((.*)\)/)
	{
	    $config_header_line = $.;
	    $config_name = $1;
	    if ($config_name =~ /^([^:]+):(.+)$/)
	    {
		$config_name = $1;
		$config_header = $2;
	    }
	    else
	    {
		$config_header = $config_name . '.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/;

	$seen_path_xtra = 1 if /AC_PATH_XTRA/;

        # This macro handles several different things.
        if (/$AM_INIT_AUTOMAKE_PATTERN/o)
	{
	    $seen_make_set = 1;
	    $seen_package = 1;
	    $seen_version = 1;
	    $seen_arg_prog = 1;
	    $seen_prog_install = 2;
	    ($package_version = $1) =~ s/$AM_PACKAGE_VERSION_PATTERN/$1/o;
	    $package_version_line = $.;
	}

	# This is like AM_INIT_AUTOMAKE, but doesn't actually set the
	# package and version number.  (This might change in the
	# future).  Yes, I'm not above hacking Automake so it works
	# well with other GNU tools -- that is actually the point.
	if (/AM_INIT_GUILE_MODULE/)
	{
	    $seen_make_set = 1;
	    $seen_package = 1;
	    $seen_version = 1;
	    $seen_arg_prog = 1;
	    $seen_prog_install = 1;
	    @config_aux_path = ('..');
	}

	# Some things required by Automake.
	$seen_make_set = 1 if /AC_PROG_MAKE_SET/;
	$seen_arg_prog = 1 if /AC_ARG_PROGRAM/;

	if (/AC_PROG_(YACC|RANLIB|CC|CXX|LEX)/)
	{
	    $configure_vars{$1} = 1;
	}
	if (/$AC_CHECK_PATTERN/o)
	{
	    $configure_vars{$3} = 1;
	}
	if (/$AC_SUBST_PATTERN/o)
	{
	    $configure_vars{$1} = 1;
	}

        $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/;
        $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/;
        $seen_package = 1 if /PACKAGE=/;

        if (/VERSION=(\S+)/)
	{
	    $seen_version = 1;
	    $package_version = $1;
	    $package_version_line = $.;
	}
        elsif (/VERSION=/)
	{
	    $seen_version = 1;
	}

        # Weird conditionals here because it is always allowed to
        # upgrade to AM_PROG_INSTALL but never to downgrade to
        # AC_PROG_INSTALL.
	$seen_prog_install = 1 if ! $seen_prog_install && /AC_PROG_INSTALL/;
	$seen_prog_install = 2 if /AM_PROG_INSTALL/;

        $seen_lispdir = 1 if /AM_PATH_LISPDIR/;

        if (/AM_PROG_LIBTOOL/)
	{
	    $seen_libtool = 1;
	    $libtool_line = $.;
	    $configure_vars{'RANLIB'} = 1;
	}
    }

    # Set input files if not specified by user.
    @input_files = @make_list if (! @input_files);

    close (CONFIGURE);

    &am_conf_error ("\`PACKAGE' not defined in configure.in")
        if ! $seen_package;
    &am_conf_error ("\`VERSION' not defined in configure.in")
        if ! $seen_version;

    # 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.
    local ($relative_dir) = '.';
    &require_config_file ($FOREIGN, 'install-sh', 'mkinstalldirs');
    &am_error ("\`install.sh' is an anachronism; use \`install-sh' instead")
        if -f $config_aux_path[0] . '/install.sh';
}

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

# 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)
    {
	if (defined $options{'no-installman'})
	{
	    &am_line_error ('AUTOMAKE_OPTIONS',
			    "option \`no-installman' disallowed by GNU standards");
	}

	if (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 ($strictness >= $GNITS)
    {
	if (-f $relative_dir . '/COPYING.LIB')
	{
	    &am_error ("\`${relative_dir}/COPYING.LIB' disallowed by Gnits standards");
	}

	if ($relative_dir eq '.')
	{
	    if ($package_version !~ /^$GNITS_VERSION_PATTERN$/)
	    {
		&am_conf_line_error ($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 ($GNITS, 'README-alpha');
	    }
	}
    }

    if ($relative_dir eq '.')
    {
	# In top level (or only) directory.
	&require_file ($GNITS, 'THANKS');
    }
}

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

# 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
{
    local ($head, $fill, @values) = @_;

    local ($column) = length ($head);
    local ($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.
    local ($fill_length) = length ($fill);
    $fill_length += 7 * ($fill =~ tr/\t/\t/d);

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

	$result .= ' ' unless ($bol);
	$result .= $_;
	$column += length ($_) + 1;
	$bol = 0;
    }

    $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 (@_);
}


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

# See if a variable exists.
sub variable_defined
{
    local ($var) = @_;
    if (defined $targets{$var})
    {
	&am_line_error ($var, "\`$var' is target; expected variable");
	return 0;
    }
    elsif (defined $contents{$var})
    {
	$content_seen{$var} = 1;
	return 1;
    }
    return 0;
}

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

# Return contents of variable as list, split as whitespace.  This will
# recursively follow $(...) and ${...} inclusions.  It preserves @...@
# substitutions.  If PARENT is specified, it is the name of the
# including variable; this is only used for error reports.
sub variable_value_as_list
{
    local ($var, $parent) = @_;
    local (@result);

    if (defined $targets{$var})
    {
	&am_line_error ($var, "\`$var' is target; expected variable");
    }
    elsif (! defined $contents{$var})
    {
	&am_line_error ($parent, "variable \`$var' not defined");
    }
    else
    {
	$content_seen{$var} = 1;
	foreach (split (' ', $contents{$var}))
	{
	    # If a comment seen, just leave.
	    last if /^#/;

	    # Handle variable substitutions.
	    if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/)
	    {
		push (@result, &variable_value_as_list ($1, $var));
	    }
	    else
	    {
		push (@result, $_);
	    }
	}
    }

    return @result;
}

# Define a new variable, but only if not already defined.
sub define_variable
{
    local ($var, $value) = @_;

    if (! defined $contents{$var})
    {
	$output_vars .= $var . ' = ' . $value . "\n";
	$contents{$var} = $value;
	$content_seen{$var} = 1;
    }
}

# Like define_variable, but second arg is a list, and is
# pretty-printed.
sub define_pretty_variable
{
    local ($var, @value) = @_;
    if (! defined $contents{$var})
    {
	$contents{$var} = join (' ', @value);
	&pretty_print ($var . ' = ', '', @value);
	$content_seen{$var} = 1;
    }
}

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

# Define a variable that represents a program to run.  If in Cygnus
# mode, the program is searched for in the build (or source) tree.
# Otherwise no searching is done at all.  Arguments are:
# * VAR      Name of variable to define
# * WHATDIR  Either `src' or `build', depending on where program should
#            be found.  (runtest is in srcdir!)
# * SUBDIR   Subdir of top-level dir
# * PROGRAM  Name of program
sub define_program_variable
{
    local ($var, $whatdir, $subdir, $program) = @_;

    if ($cygnus_mode)
    {
	local ($full) = ('$(top_' . $whatdir . 'dir)/../'
			 . $subdir . '/' . $program);
	&define_variable ($var, ('`if test -f ' . $full
				 . '; then echo ' . $full . '; else echo '
				 . $program . '; fi`'));
    }
    else
    {
	&define_variable ($var, $program);
    }
}


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

# 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
{
    local ($amfile) = @_;

    open (AM_FILE, $amfile) || die "automake: couldn't open \`$amfile': $!\n";
    print "automake: reading $amfile\n" if $verbose;

    $output_vars = ("# $in_file_name generated automatically by automake "
		    . $VERSION . " from $am_file_name\n");

    # Generate copyright for generated Makefile.in.
    $output_vars .= $gen_copyright;

    local ($saw_bk) = 0;
    local ($was_rule) = 0;
    local ($spacing) = '';
    local ($comment) = '';
    local ($last_var_name) = '';
    local ($blank) = 0;

    while (<AM_FILE>)
    {
	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";
    local ($am_vars) = '';

    local ($is_ok_macro);
    while ($_)
    {
	$_ .= "\n"
	    unless substr ($_, -1, 1) eq "\n";

	$_ =~ 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";
	}
	elsif (/$COMMENT_PATTERN/o)
	{
	    # Stick comments before the incoming macro or rule.
	    $comment .= $spacing . $_;
	    $spacing = '';
	}
	elsif ($saw_bk)
	{
	    if ($was_rule)
	    {
		$output_trailer .= $_;
		$saw_bk = /\\$/;
	    }
	    else
	    {
		$am_vars .= $_;
		$saw_bk = /\\$/;
		# Chop newline and backslash if this line is
		# continued.  FIXME: maybe ensure trailing whitespace
		# exists?
		chop if $saw_bk;
		chop if $saw_bk;
		$contents{$last_var_name} .= $_;
	    }
	}
	elsif (/$RULE_PATTERN/o)
	{
	    # warn "** Saw rule .$1.\n";
	    # Found a rule.
	    $was_rule = 1;
	    # Value here doesn't matter; for targets we only note
	    # existence.
	    $contents{$1} = 1;
	    $targets{$1} = 1;
	    $content_lines{$1} = $.;
	    $output_trailer .= $comment . $spacing . $_;
	    $comment = $spacing = '';
	    $saw_bk = /\\$/;
	}
	elsif (($is_ok_macro = /$MACRO_PATTERN/o)
	       || /$BOGUS_MACRO_PATTERN/o)
	{
	    # Found a macro definition.
	    $was_rule = 0;
	    $last_var_name = $1;
	    if (substr ($2, -1) eq "\\")
	    {
		$contents{$1} = substr ($2, 0, length ($2) - 1);
	    }
	    else
	    {
		$contents{$1} = $2;
	    }
	    $content_lines{$1} = $.;
	    $am_vars .= $comment . $spacing . $_;
	    $comment = $spacing = '';
	    $saw_bk = /\\$/;

	    # Error if bogus.
	    &am_line_error ($., "bad macro name \`$1'")
		if ! $is_ok_macro;
	}
	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 . $_;
	    $comment = $spacing = '';
	    $saw_bk = /\\$/;
	}

	$_ = <AM_FILE>;
    }

    $output_trailer .= $comment;

    # Compute relative location of the top object directory.
    local (@topdir) = ();
    foreach (split (/\//, $relative_dir))
    {
	next if $_ eq '.' || $_ eq '';
	if ($_ eq '..')
	{
	    pop @topdir;
	}
	else
	{
	    push (@topdir, '..');
	}
    }
    @topdir = ('.') if ! @topdir;

    $top_builddir = join ('/', @topdir);
    local ($build_rx);
    ($build_rx = $top_builddir) =~ s/(\W)/\\$1/g;
    $output_vars .= &file_contents_with_transform
                        ('s/\@top_builddir\@/' . $build_rx . '/g',
			 'header-vars');

    # Generate some useful variables when AC_CANONICAL_* used.  FIXME:
    # this should use generic %configure_vars method.
    if ($seen_canonical)
    {
	local ($curs, %vars);
	$vars{'host_alias'} = 'host_alias';
	$vars{'host_triplet'} = 'host';
	if ($seen_canonical == $AC_CANONICAL_SYSTEM)
	{
	    $vars{'build_alias'} = 'build_alias';
	    $vars{'build_triplet'} = 'build';
	    $vars{'target_alias'} = 'target_alias';
	    $vars{'target_triplet'} = 'target';
	}
	foreach $curs (keys %vars)
	{
	    $output_vars .= "$curs = \@$vars{$curs}\@\n";
	    $contents{$curs} = "\@$vars{$curs}\@";
	}
    }

    local ($curs);
    foreach $curs (keys %configure_vars)
    {
	&define_configure_variable ($curs);
    }

    $output_vars .= $am_vars;
}

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

sub initialize_global_constants
{
    # Values for AC_CANONICAL_*
    $AC_CANONICAL_HOST = 1;
    $AC_CANONICAL_SYSTEM = 2;

    # Associative array of standard directory names.  Entry is TRUE if
    # corresponding directory should be installed during
    # 'install-exec' phase.
    %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
	 );

    # Helper text for dealing with man pages.
    $install_man_format =
    '	sect=@SECTION@;				\\
	inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
	if test -f $(srcdir)/@MAN@; then file=$(srcdir)/@MAN@; \\
	else file=@MAN@; fi; \\
	$(INSTALL_DATA) $$file $(mandir)/man$$sect/$$inst
';

    $uninstall_man_format =
    '	inst=`echo "@MANBASE@" | sed \'$(transform)\'`.@FULLSECT@; \\
	rm -f $(mandir)/man@SECTION@/$$inst
';

    # Commonly found files we look for and automatically include in
    # DISTFILES.
    @common_files =
	(
	 "README", "THANKS", "TODO", "NEWS", "COPYING", "COPYING.LIB",
	 "INSTALL", "ABOUT-NLS", "ChangeLog", "configure", "configure.in",
	 "config.guess", "config.sub", "AUTHORS", "BACKLOG", "ABOUT-GNU",
	 "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
	 'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
	 'interlock', 'ylwrap', 'acinclude.m4'
	 );

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

    $USAGE = "\
  -a, --add-missing     add missing standard files to package
  --amdir=DIR           directory storing config files
  --build-dir=DIR       directory where build being done (for dependencies)
  --cygnus              assume program is part of Cygnus-style tree
  --foreign             same as --strictness=foreign
  --gnits               same as --strictness=gnits
  --gnu                 same as --strictness=gnu
  --help                print this help, then exit
  -i, --include-deps    include generated dependencies in Makefile.in
  --no-force            only update Makefile.in's that are out of date
  -o DIR, --output-dir=DIR
                        put generated Makefile.in's into DIR
  --srcdir-name=DIR     name used for srcdir (for dependencies)
  -s LEVEL, --strictness=LEVEL
                        set strictness level.  LEVEL is foreign, gnu, gnits
  -v, --verbose         verbosely list files processed
  --version             print version number, then exit\n";

    # Copyright on generated Makefile.ins.
    $gen_copyright = "\
# Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
";

    # Ignore return result from chmod, because it might give an error
    # if we chmod a symlink.
    $dist_header = "\t" . '-chmod -R a+r $(distdir)' . "\n";
    $dist{'tarZ'} = ("\t"
		     . '$(TAR) chf - $(distdir) | compress -c > $(distdir).tar.Z'
		     . "\n");
    $dist{'shar'} = ("\t"
		     . 'shar $(distdir) | gzip > $(distdir).shar.gz'
		     . "\n");
    $dist{'zip'} = "\t" . 'zip -rq $(distdir).zip $(distdir)' . "\n";
    $dist{'dist'} = "\t" .  '$(TAR) chozf $(distdir).tar.gz $(distdir)' . "\n";
    $dist_trailer = "\t" . 'rm -rf $(distdir)' . "\n";
}

# (Re)-Initialize per-Makefile.am variables.
sub initialize_per_input
{
    # These two variables are used when generating each Makefile.in.
    # They hold the Makefile.in until it is ready to be printed.
    $output_rules = '';
    $output_vars = '';
    $output_trailer = '';

    # Suffixes found during a run.
    @suffixes = ();

    # This holds the contents of a Makefile.am, as parsed by
    # read_am_file.
    %contents = ();

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

    # This holds the line numbers at which various elements of
    # %contents are defined.
    %content_lines = ();

    # This holds a 1 if a particular variable was examined.
    %content_seen = ();

    # This holds the "relative directory" of the current Makefile.in.
    # Eg for src/Makefile.in, this is "src".
    $relative_dir = '';

    # This holds a list of files that are included in the
    # distribution.
    %dist_common = ();

    # List of dependencies for the obvious targets.
    @install_data = ();
    @install_exec = ();
    @uninstall = ();
    @installdirs = ();

    @info = ();
    @dvi = ();
    @all = ();
    @check = ();
    @installcheck = ();
    @clean = ();

    @phony = ();

    # These are pretty obvious, too.  They are used to define the
    # SOURCES and OBJECTS variables.
    @sources = ();
    @objects = ();

    # TRUE if current directory holds any C source files.  (Actually
    # holds object extension, but this information is encapsulated in
    # the function get_object_extension).
    $dir_holds_sources = '';

    # TRUE if current directory holds any headers.
    $dir_holds_headers = 0;

    # TRUE if install targets should work recursively.
    $recursive_install = 0;

    # All .P files.
    %dep_files = ();

    # Strictness levels.
    $strictness = $default_strictness;
    $strictness_name = $default_strictness_name;

    # Options from AUTOMAKE_OPTIONS.
    %options = ();

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

    # Per Makefile.am.
    $local_maint_charset = $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).
    %yacc_sources = ();
    %lex_sources = ();

    # C++ source extensions we've seen.
    %cxx_extensions = ();

    # TRUE if we've seen any non-C++ sources.
    $seen_c_source = 0;

    # This is a list of all targets to run during "make dist".
    @dist_targets = ();
}


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

# Return contents of a file from $am_dir, automatically skipping
# macros or rules which are already known.  Runs command on each line
# as it is read; this command can modify $_.
sub file_contents_with_transform
{
    local ($command, $basename) = @_;
    local ($file) = $am_dir . '/' . $basename . '.am';

    open (FC_FILE, $file)
	|| die "automake: installation error: cannot open \`$file'\n";
    # Looks stupid?
    # print "automake: reading $file\n" if $verbose;

    local ($was_rule) = 0;
    local ($result_vars) = '';
    local ($result_rules) = '';
    local ($comment) = '';
    local ($spacing) = "\n";
    local ($skipping) = 0;

    while (<FC_FILE>)
    {
	$_ =~ s/\@MAINT\@//g
	    unless $seen_maint_mode;

	eval $command;

	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";
	}
	elsif (/$COMMENT_PATTERN/o)
	{
	    # Stick comments before the incoming macro or rule.
	    $comment .= $spacing . $_;
	    $spacing = '';
	}
	elsif ($saw_bk)
	{
	    if ($was_rule)
	    {
		$result_rules .= $_ if ! $skipping;
	    }
	    else
	    {
		$result_vars .= $_ if ! $skipping;
	    }
	    $saw_bk = /\\$/;
	}
	elsif (/$RULE_PATTERN/o)
	{
	    # warn "** Found rule .$1.\n";
	    # Found a rule.
	    $was_rule = 1;
	    $skipping = defined $contents{$1};
	    # warn "** Skip $skipping\n" if $skipping;
	    $result_rules .= $comment . $spacing . $_ if ! $skipping;
	    $comment = $spacing = '';
	    $saw_bk = /\\$/;
	}
	elsif (/$MACRO_PATTERN/o)
	{
	    # warn "** Found macro .$1.\n";
	    # Found a variable reference.
	    $was_rule = 0;
	    $skipping = defined $contents{$1};
	    # warn "** Skip $skipping\n" if $skipping;
	    $result_vars .= $comment . $spacing . $_ if ! $skipping;
	    $comment = $spacing = '';
	    $saw_bk = /\\$/;
	}
	else
	{
	    # This isn't an error; it is probably a continued rule.
	    # In fact, this is what we assume.
	    $was_rule = 1;
	    $result_rules .= $comment . $spacing . $_ if ! $skipping;
	    $comment = $spacing = '';
	    $saw_bk = /\\$/;
	}
    }

    close (FC_FILE);
    return $result_vars . $result_rules . $comment;
}

# Like file_contents_with_transform, but no transform.
sub file_contents
{
    return &file_contents_with_transform ('', @_);
}

# 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
{
    local ($primary, @prefixes) = @_;

    local (%valid, $varname);
    grep ($valid{$_} = 0, @prefixes);
    $valid{'EXTRA'} = 0;
    foreach $varname (keys %contents)
    {
	if ($varname =~ /^(.*)_$primary$/)
	{
	    if (! defined $valid{$1} && ! &variable_defined ($1 . 'dir'))
	    {
		&am_line_error ($varname, "invalid variable \"$varname\"");
	    }
	    else
	    {
		# Ensure all extended prefixes are actually used.
		$valid{$1} = 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
{
    local (@args) = @_;

    local ($do_all, $do_clean) = (1, 0);
    while (@args)
    {
	if ($args[0] eq '-clean')
	{
	    $do_clean = 1;
	}
	elsif ($args[0] eq '-no-all')
	{
	    $do_all = 0;
	}
	elsif ($args[0] !~ /^-/)
	{
	    last;
	}
	shift (@args);
    }
    local ($file, $primary, @prefixes) = @args;

    local (@used) = ();
    local (@result) = ();

    # Now that configure substitutions are allowed in where_HOW
    # variables, it is an error to actually define the primary.
    &am_line_error ($primary, "\`$primary' is an anachronism")
	if &variable_defined ($primary);


    # 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.  Perhaps it should be
    # disallowed in the Gnits case?  The problem is, sometimes it is
    # useful to put things in a subdir of eg pkgdatadir, perhaps even
    # for Gnitsoids.
    local (%valid) = &am_primary_prefixes ($primary, @prefixes);

    # If a primary includes a configure substitution, then the EXTRA_
    # form is required.  Otherwise we can't properly do our job.
    local ($require_extra);
    local ($warned_about_extra) = 0;

    local ($clean_file) = $file . '-clean';
    local ($one_name);
    local ($X);
    foreach $X (keys %valid)
    {
	$one_name = $X . '_' . $primary;
	if (&variable_defined ($one_name))
	{
	    # Append actual contents of where_PRIMARY variable to
	    # result.
	    local ($rcurs);
	    foreach $rcurs (&variable_value_as_list ($one_name))
	    {
		# 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");
			}
		    }
		    else
		    {
			$require_extra = $one_name;
		    }
		    next;
		}
		push (@result, $rcurs);
	    }

	    # "EXTRA" shouldn't be used when generating clean targets,
	    # @all, or install targets.
	    next if $X eq 'EXTRA';

	    if ($do_clean)
	    {
		$output_rules .=
		    &file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
						   $clean_file);

		push (@clean, $X . $primary);
		&push_phony_cleaners ($X . $primary);
	    }

	    if ($X eq 'check')
	    {
		push (@check, '$(' . $one_name . ')');
	    }
	    else
	    {
		push (@used, '$(' . $one_name . ')');
	    }
	    if ($X eq 'noinst' || $X eq 'check')
	    {
		# Objects which don't get installed by default.
		next;
	    }

	    $output_rules .=
		&file_contents_with_transform ('s/\@DIR\@/' . $X . '/go',
					       $file);

	    push (@uninstall, 'uninstall-' . $X . $primary);
	    push (@phony, 'uninstall-' . $X . $primary);
	    push (@installdirs, '$(' . $X . 'dir)');
	    if ($exec_dir_p{$X})
	    {
		push (@install_exec, 'install-' . $X . $primary);
		push (@phony, 'install-' . $X . $primary);
	    }
	    else
	    {
		push (@install_data, 'install-' . $X . $primary);
		push (@phony, 'install-' . $X . $primary);
	    }
	}
    }

    if (@used)
    {
	# 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 $do_all && @used;

    return (@result);
}


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

# This variable is local to the "require file" set of functions.
@require_file_paths = ();

# Verify that the file must exist in the current directory.  Usage:
# require_file (isconfigure, line_number, strictness, file) strictness
# 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
{
    local ($is_configure, $line, $mystrict, @files) = @_;
    local ($file, $fullfile);
    local ($found_it, $errfile, $errdir);
    local ($save_dir);

    foreach $file (@files)
    {
	$found_it = 0;
	foreach $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 (-f $fullfile)
	    {
		$found_it = 1;
		# FIXME: Once again, special-case `.'.
		&push_dist_common ($file)
		    if $dir eq $relative_dir || $dir eq '.';
		$save_dir = $dir;
		last;
	    }
	}

	if ($found_it)
	{
	    # Prune the path list.
	    @require_file_paths = $save_dir;
	}
	else
	{
	    if ($strictness >= $mystrict)
	    {
		local ($trailer) = '';
		local ($suppress) = 0;

		# Only install missing files according to our desired
		# strictness level.
		if ($add_missing && -f ($am_dir . '/' . $file))
		{
		    $trailer = "; installing";
		    $suppress = 1;
		    # Install the missing file.  Symlink if we can,
		    # copy if we must.  Note: delete the file first,
		    # in case it is a dangling symlink.
		    unlink ($errfile);
		    if ($symlink_exists)
		    {
			if (! symlink ($am_dir . '/' . $file, $errfile))
			{
			    $suppress = 0;
			    $trailer .= "; error while making link: $!\n";
			}
		    }
		    else
		    {
			if (! system ('cp', $am_dir . '/' . $file, $errfile))
			{
			    $suppress = 0;
			    $trailer .= "\n    error while making link: $!\n";
			}
		    }
		}

		local ($save) = $exit_status;
		if ($is_configure)
		{
		    &am_conf_line_error
			($line,
			 "required file \"$errfile\" not found$trailer");
		}
		else
		{
		    &am_line_error
			($line,
			 "required file \"$errfile\" not found$trailer");
		}
		$exit_status = $save if $suppress;
	    }
	}
    }
}

# Like require_file_with_line, but error messages refer to
# configure.in, 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, '', @_);
    local ($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, @_);
    local ($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_conf_line
{
    @require_file_paths = @config_aux_path;
    &require_file_internal (1, @_);
    local ($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
{
    local (@files) = @_;
    local ($file);

    foreach $file (@files)
    {
	$dist_common{$file} = 1;
    }
}

# Push a list of clean targets onto phony.
sub push_phony_cleaners
{
    local ($base) = @_;
    local ($target);
    foreach $target ('mostly', 'dist', '', 'maintainer-')
    {
	push (@phony, $target . 'clean-' . $base);
    }
}

# 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 "automake: level \`$strictness_name' not recognized\n";
    }
}


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

# Return directory name of file.
sub dirname
{
    local ($file) = @_;
    local ($sub);

    ($sub = $file) =~ s,/+[^/]+$,,g;
    $sub = '.' if $sub eq $file;
    return $sub;
}

# Return file name of a file.
sub basename
{
    local ($file) = @_;
    local ($sub);

    ($sub = $file) =~s,^.*/+,,g;
    return $sub;
}

# Touch a file.
sub touch
{
    local ($file) = @_;

    open (TOUCH, ">> $file");
    close (TOUCH);
}

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

# Print an error message and set exit status.
sub am_error
{
    warn "automake: ${am_file}.am: ", join (' ', @_), "\n";
    $exit_status = 1;
}

sub am_line_error
{
    local ($symbol, @args) = @_;

    if ($symbol)
    {
	# If SYMBOL not already a line number, look it up in Makefile.am.
	$symbol = $content_lines{$symbol} unless $symbol =~ /^\d+$/;
	$symbol .= ': ' if $symbol;
	warn "${am_file}.am:", $symbol, join (' ', @args), "\n";
	$exit_status = 1;
    }
    else
    {
	&am_error (@args);
    }
}

# Like am_error, but while scanning configure.in.
sub am_conf_error
{
    # FIXME: can run in subdirs.
    warn "automake: configure.in: ", join (' ', @_), "\n";
    $exit_status = 1;
}

# Error message with line number referring to configure.in.
sub am_conf_line_error
{
    local ($line, @args) = @_;

    if ($line)
    {
	warn "configure.in: $line: ", join (' ', @args), "\n";
	$exit_status = 1;
    }
    else
    {
	&am_conf_error (@args);
    }
}

# Tell user where our aclocal.m4 is, but only once.
sub keyed_aclocal_warning
{
    local ($key) = @_;
    warn "automake: macro \`$key' can be generated by \`aclocal'\n";
}

# Print usage information.
sub usage
{
    print "Usage: automake [OPTION] ... [Makefile]...\n";
    print $USAGE;
    print "\nFiles which are automatically distributed, if found:\n";
    $~ = "USAGE_FORMAT";
    local (@lcomm) = sort ((@common_files, @common_sometimes));
    local ($one, $two, $three, $four);
    while (@lcomm > 0)
    {
	$one = shift @lcomm;
	$two = @lcomm ? shift @lcomm : '';
	$three = @lcomm ? shift @lcomm : '';
	$four = @lcomm ? shift @lcomm : '';
	write;
    }

    print "\nReport bugs to <bug-gnu-utils\@prep.ai.mit.edu>\n";

    exit 0;
}

format USAGE_FORMAT =
  @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
  $one,               $two,               $three,             $four
.