summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/ctan2tds
blob: 6332732d6c3cd3ade5ea97190eb58a7eaeb4720c (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
#!/usr/bin/env perl
# $Id$
# Public domain.
# Originally written by Sebastian Rahtz.  Comments to tex-live@tug.org.
# 
# A script to TL-install a package from CTAN.
# For a higher-level invocation, see ctan2tl.
# 
# Its default actions, given a "raw" directory copied from CTAN (the
# current directory on invocation), are
#  1. copy everything to texmf-dist/doc/<format>/<package>
#  2. run any .ins files
#  3. run any .mf files through mktextfm
#  4. move .sty/.cls etc files to texmf-dist/tex/<format>/<package>
#  5. move other files to appropriate places in the hierarchy.
#  
# All the patterns for what to move or run can be overridden per-package.

use English;
use Getopt::Long;
use File::Basename;
use Cwd;
#
# programs used; must all be on the path
$MV = "mv";
$CP = "cp -p";
$RM = "rm -vf";  # just to get feedback from GNU rm on removals

$| = 1;
select ((select (STDERR), $| = 1)[0]);

$startdir = getcwd();  # where we start from (raw dir)
chdir "../tmp.cooked" || die "chdir(../tmp.cooked) failed: $!";
$TDS = getcwd();       # locate destination dir
chdir $startdir || die "chdir($startdir) failed: $!";  # back to raw

# 
# packages to treat entirely on their own, or not at all.
# the code here is evaluated by Perl, so special packages
# can have their own subroutine.
#
%special = (
 'Catalogue',	"&MAKECatalogue",
 'FAQ-en',	"&MAKEFAQen",
 'HA-prosper',	'&MAKEhaprosper',
 'IEEEtran',	"&MAKEIEEEtran",
 'LingTrees',	"die 'skipping, requires python'",
 'SIstyle',	'&MAKEflatten',
 'a4',		"die 'skipping, just a pointer to ntgclass'",
 'aastex',	"&MAKEflatten",
 'aeb_pro',	"die 'skipping, requires new acrobat + complicated'",
 'amscls',	"die 'skipping, ams situation confused'",
 'arabxetex',	'&MAKEflatten',
 'ae',		"&MAKEae",
 'AkkTeX',	"&MAKEflatten",
 'algorithmicx',"&MAKEnosymlinks",
 'allrunes',	"&MAKEflatten",
 'alphabib',	"die 'skipping, shell script, and no doc source?'",
 'ams',		"die 'skipping, update manually to preserve ams fonts'",
 'amsldoc-vn',	"&MAKEflatten",
 'antomega',	"&MAKEflatten",
 'antt',	"&MAKEcopy",
 #'antp',        "&MAKEflatten", # not sure about config.antp yet
 'apacite',	"&MAKEflatten",
 'arabi',	"&MAKEarabi",
 'arabtex',	"&MAKEarabtex",
 'archaic',	"&MAKEwilson",
 'arphic',	"&MAKEarphic",
 'arev',	"&MAKEcopy",
 'ascii',	"&MAKEflatten",
 'astron',	"die 'skipping, nonfree license'",
 'augie',	"&MAKEaugie",
 'aurical',	"&MAKEaurical",
 'aurora',	"die 'skipping, nocommercial license'",
 'bangtex',	"&MAKEflatten",
 'bardiag',	"&MAKEbardiag",
# bbm is split into bbm (fonts) and bbm-macros (macros)
# 'bbm',		"&MAKEbbm",
 'beamer',	"&MAKEbeamer",
 'beamer-contrib',"&MAKEflatten",
 'beebe',	"die 'skipping, MAKEbeebe needs work, sorry'",
 'bengali',	'&MAKEflatten',
 'bengali-omega',	"die 'skipping, duplicates odev.sty et al.'",
 'bera',	"&MAKEunzipandflatten",
 'biblatex',	"die 'skipping, still experimental'",
 'biblatex-dw',	"die 'skipping, depends on experimental biblatex'",
 'biblatex-mla',"die 'skipping, depends on experimental biblatex'",
 'bibtopicprefix', "&MAKEflatten",
 'bitfield',	"die 'skipping, obsolete on CTAN'",
 'blanks',	"die 'skipping, unknown license (and c.1992)'",
 'blockdraw_mp',"&MAKEflatten",
 'bnf-plain',	"die 'skipping, unknown license (and c.1992)'",
 'bookhands',	"&MAKEwilson",
 'borceux',	"&MAKEborceux",
 'burmese',	"&MAKEflatten",
 'calendar',	"die 'skipping, nosell license'",
 'camel',	"die 'skipping, nosell license'",
 'cbfonts',	"&MAKEflatten",
 'cbcoptic',	"&MAKEcbcoptic",
 'changebar',	"&MAKEchangebar",
 #'chemarrow',   "&MAKEflatten", # check about Arrow.vfb
 'chemsym',	"die 'skipping, nonfree'",
 'cheq',	"die 'skipping, nosell license'",
 'circuit_macros', "die 'skipping, needs m4'",
 'cjhebrew',	"&MAKEflatten",
 'cjk',		"&MAKEcjk",
 'clock',	"&MAKEflatten",
 'cm-lgc',	'&MAKEcmlgc',
 'cm-super',	"&MAKEflatten",
 'cmbright',	"&MAKEflatten",
 'cmcyr',	"&MAKEflatten",
 'cmll',	"&MAKEflatten",
 'comicsans',	"die 'skipping, Comic Sans is nonfree'",
 'concmath',	"&MAKEconcmath",
 'context',	"&MAKEcontext",
 'context-account',   "&MAKEcopy",
 'context-bnf',       "&MAKEcopy",
 'context-chromato',  "&MAKEcopy",
 'context-construction-plan', "&MAKEcopy",
 'context-degrade',   "&MAKEcopy",
 'context-french',    "&MAKEcopy",
 'context-letter',    "&MAKEcopy",
 'context-lettrine',  "&MAKEcopy",
 'context-lilypond',  "&MAKEcopy",
 'context-mathsets',  "&MAKEcopy",
 'context-taspresent',"&MAKEcopy",
 'context-typearea',  "&MAKEcopy",
 'context-vim',       "&MAKEcopy",
 'coptic',	"die 'skipping, it has been replaced by cbcoptic'",
 'corridx',	"die 'skipping, Pascal source'",
 'csplain',	"die 'skipping, too hard to automate'",
 'csvtools',	"&MAKEflatten",
 'ctable',	"&MAKEflatten",
 'ctib',	"&MAKEflatten",
 'cweb',	"die 'skipping, programs'",
 'cyklop',      "&MAKEcopy",
 'deleq',	"die 'skipping, nosell license'",
 'devanagr',	"&MAKEdevanagr",
 'diagnose',	"&MAKEflatten",
 'dictsym',	"&MAKEunzipandflatten",
 'disser',	"&MAKEdisser",
 'dmfonts',	"die 'skipping, needs work'",
 'dogma',	"die 'skipping, requires nonfree font'",
 'dot2tex',	"die 'skipping, only useful with supporting programs'",
 'dot2texi',	"die 'skipping, only useful with supporting programs'",
 'dps',		"die 'skipping, requires acrotex'",
 'dropping',	"die 'skipping, nosell license'",
 'dtk',		"&MAKEflatten",
 'dtxtut',	"&setup",  # straight copy
 'easy',	"&MAKEeasy",
 'ean13isbn',   "&MAKEcopy",
 'ebib',	"die 'skipping, as it is Emacs'",
 'ebong',	"&MAKEebong",
 'ecc',		"&MAKEflatten",
 'eco',		"&MAKEeco",
 'edmac',	"die 'skipping, needs work (unzip xx)'",
 'ednotes',	"&MAKEnosymlinks",
 'elhyphen',	"die 'incorporated in hyph-utf8'",
 'encxvlna',    "&MAKEcopy",
 'enpassant',	"die 'skipping, license unknown'",
 'epic',	"die 'skipping, license unknown and replaced by eepic'",
 'epigrafica',	"&MAKEflatten",
 'epiolmec',	"&MAKEflatten",
 'epix',	"die 'skipping, needs C++'",
 'eplain',	"&MAKEcopy",
 'epstopdf',	"die 'skipping, needs .pl vs. noext + man help, sorry'",
 'eskdx',	"&MAKEeskdx",
 'esvect',	"&MAKEflatten",
 'ethiop',	"&MAKEflatten",
 'euclide',	"&MAKEpst",
 'eulervm',	"&MAKEcopy",
 'eurosym',	"&MAKEflatten",
 #'euenc',	"&MAKEflatten",
 'expressgx',	"&MAKEexpressg",
 'fancyvrb',	"&MAKEfancyvrb",
 'faq-fr',	"die 'skipping, non-free'",
 'fc',		"&MAKEflatten",
 'featpost',	"&MAKEfeatpost",
 'feynmf',	"&MAKEfeynmf",
 'floatflt',	"die 'skipping, nosell license'",
 'foiltex',     "die 'skipping, non-free (nosell)'",
 'flowfram',	"&MAKEflatten",
 'fontinst',	"&MAKEfontinst",
 'footnpag',	"&MAKEfootnpag",
 'fourier',	"&MAKEflatten",
 'fouriernc',	"&MAKEflatten",
 'fp',		"&MAKEfp",
 'fpl',		"&MAKEflatten",
 'fragments',	"die 'skipping, not a package'",
 'frcursive',	"&MAKEflatten",
 'futurans',	"die 'skipping, requires nonfree font'",
 'galley',      "die 'skipping, will be included in xpackages later'",
 'genmisc',	"die 'too complicated, sorry'",
 'germbib',	"&MAKEgermbib",
 'gfsartemisia',"&MAKEflatten",
 'gfsbaskerville',"&MAKEflatten",
 'gfsbodoni',   "&MAKEflatten",
 'gfsdidot',    "&MAKEflatten",
 'gfscomplutum',"&MAKEflatten",
 'gfsneohellenic', "&MAKEflatten",
 'gfsporson',   "&MAKEflatten",
 'gfssolomos',  "&MAKEflatten",
 'glhyph',	"die 'merged into hyph-utf8'",
 'graphicxsp',	"die 'skipping, requires adobe distiller'",
 'grtimes',	"die 'skipping, requires nonfree monotype times'",
 'hfbright',	"&MAKEflatten",
 'hfoldsty',	"&MAKEflatten",
 'hyph-utf8',	"&MAKEcopy",
 'hyphen-german',"die 'please install hyphen-german by hand, sorry'",
 'ibycus-babel',"&MAKEibycusbabel",
 'ibygrk',	"&MAKEflatten",
 'ifacmtg',	"die 'skipping, nonfree license'",
 'invoice',	"&MAKEflatten",
 'iwona',	"&MAKEcopy",
 'japanese',	"die 'skipping, requires ptex'",
 'jasthesis',	"die 'skipping, license is unknown'",
 'javadoc',	"die 'skipping, requires java and no source'",
 'jj_game',	"die 'skipping, requires acrotex'",
 'jsclasses',	"die 'skipping, requires nonfree ptex/platex'",
 'kerkis',	"&MAKEflatten",
 'kurier',	"&MAKEcopy",
 'kuvio',	"die 'skipping, nonfree license'",
 'latex-veryshortguide', "die 'skipping, nosell license'",
 'latexmp',	"&MAKEflatten",
 'leawood',	"&MAKEflatten",
 'lettre',	"&MAKEflatten",
 'lexitex',	"die 'skipping, camel has replaced'",
 'lfb',		"&MAKElfb",
 'lh',		"&MAKEcopy",
 'libertine',	"&MAKEcopy",
 'lifia-th',	"die 'skipping, '",
 'linearA',	"&MAKEflatten",
 "lineno",	"&MAKEnosymlinks",
 'literat',	"&MAKEliterat",
 'lm',		"&MAKEcopy",
 'lms',		"die 'skipping, nonfree license'",
 'lshort-bulgarian', 	'&MAKElshort',
 'lshort-chinese', 	'&MAKElshort',
 'lshort-english',	'&MAKElshort',
 'lshort-finnish', 	'&MAKElshort',
 'lshort-korean', 	'&MAKElshort',
 'lshort-portuguese', 	'&MAKElshort',
 'lshort-slovenian', 	'&MAKElshort',
 'lshort-turkish', 	'&MAKElshort',
 'lshort-vietnamese', 	'&MAKElshort',
 'ltt',		"&MAKEltt",
 'ltxbase',	"&MAKEbase",
 'ltxmisc',	"die 'skipping, too complicated, sorry'",
 'lxfonts',	"&MAKEcopy",
 'lucida',	"&MAKElucida",
 'magyar',      "die 'skipping, conflicts with regular babel'",
 'makecell',	"&MAKEnosymlinks",
 'makedtx',	"&MAKEflatten",
 'makor',	"&MAKEbase",
 'manjutex',	"die 'skipping, obsolete on CTAN'", #"&MAKEflatten",
 'manpage',	"die 'skipping, nonfree license'",
 'marvosym',	"&MAKEnosymlinks",
 'mathdesign',	"&MAKEmathdesign",
 'mathexam',	"&MAKEflatten",
 'mathmode',	"&setup",
 'mathpazo',	"&MAKEmathpazo",
 'matlab',	"die 'skipping, requires nonfree matlab'",
 'mdwfonts',	"die 'skipping, too many tfm duplicates'",
 'metaobj',	"&MAKEflatten",
 'metauml',	"&MAKEmetauml",
 'mflogo',	"&MAKEmflogo",
 'mfpic',	"&MAKEflatten",
 'minionpro',	"die 'skipping, requires nonfree minion'",
 'misc',	"&MAKEmisc",
 'mkbangtex',	"die 'skipping, no copyright (and python)'",
 'mlbib',	"die 'skipping, bib file names are too generic'",
 'mnhyphn',	"&MAKEmnhyphn",
 'mnsymbol',	"&MAKEflatten",
 'montex',	"&MAKEflatten",
 'morehelp',	"die 'skipping, nonfree license'",
 'morse',	"die 'skipping, nosell license'",
 'movie15',	"&MAKEflatten",
 'mpattern',	"&MAKEmpattern",
 'multido',	"&MAKEpst",
 'mwrite',	"die 'skipping, nonfree license",
 'mx'	,	"die 'skipping, author does not recommend system install'",
 'mxd',		"&MAKEflatten",
 'mxedruli',	"&MAKEflatten",
 'nbaskerv',	"die 'skipping, requires nonfree font'",
 'ncctools',	"&MAKEflatten",
 'newsletr',    "&MAKEnewsletr",
 'nohyph',	"die 'skipping, nohyph must be done by hand'",
 'ocherokee',	"&MAKEflatten",
 'ocr-a',	"die 'skipping, nosell license'",
 'oesch',	"die 'skipping, nosell license'",
 'ofs',		"&MAKEflatten",
 'omegajapanese',"&MAKEflatten",
 'osa',		"die 'skipping, relies on endfloat.cfg and non-unique filenames'",
 'ot2cyr',	"&MAKEot2cyr",
 'otibet',	"&MAKEflatten",
 'oxford',	"die 'skipping, nosell license'",
 'pandora',	"&MAKEflatten",
 'pax',		"die 'skipping, needs java'",
 'pb-diagram',	"&MAKEpbdiagram",
 'pclnfss',	"&MAKEpclnfss",
 'pdcmac',	"die 'skipping, needs work'",
 'pdf-forms-tutorial',	"die 'use pdf-forms-tutorial-de or -en'",
 'pdf-forms-tutorial-de',	"&MAKEpdf_forms_tutorial",
 'pdf-forms-tutorial-en',	"&MAKEpdf_forms_tutorial",
 'pdfrack',	"die 'skipping until someone asks for it'",
 'pgf',		"&MAKEcopy",
 'pgfplots',	"&MAKEcopy",
 'phaistos',	"&MAKEflatten",
 'pict2e',	"&MAKEpict2e",
 'pictex',	"&MAKEpictex",
 'pinlabel',	"&MAKEnosymlinks",
 'pl-qx',	"&MAKEplqx",
 'poster',	"die 'skipping, nonfree license'",
 'powerdot',	'&MAKEflatten',
 'proofs',	"die 'skipping, nosell license'",
 'prosper',	'&MAKEflatten',
 'ps4pdf',	"die 'skipping, obsolete'",
 'psfig',	"die 'skipping, nosell license'",
 'psfragx',	"&MAKEflatten",
 'pslatex',	"&MAKEpslatex",
 'psnfss',	"&MAKEpsnfss",
 'psnfss-addons', "die 'skipping, ?'",
 'psnfssx',	"&MAKEflatten",
 'pst-2dplot',	"&MAKEpst",
 'pst-3d',	"&MAKEpst",
 'pst-3dplot',	"&MAKEpst",
 'pst-asr',	"&MAKEpst",
 'pst-bar',	"&MAKEpst",
 'pst-barcode',	"&MAKEpst",
 'pst-blur',	"&MAKEpst",
 'pst-circ',	"&MAKEpst",
 'pst-coil',	"&MAKEpst",
 'pst-cox',	"&MAKEflatten",
 'pst-dbicons',	"&MAKEpst",
 'pst-diffraction', "&MAKEpst",
 'pst-eps',	"&MAKEpst",
 'pst-eucl',	"&MAKEpst",
 'pst-fill',	"&MAKEpst",
 'pst-fr3d',	"&MAKEpst",
 'pst-fractal',	"&MAKEpst",
 'pst-fun',	"&MAKEpst",
 'pst-func',	"&MAKEpst",
 'pst-geo',	"&MAKEpstgeo",
 'pst-ghsb',	"&MAKEpst",
 'pst-gr3d',	"&MAKEpst",
 'pst-grad',	"&MAKEpst",
 'pst-infixplot',"&MAKEpst",
 'pst-jftree',	"&MAKEpst",
 'pst-jtree',	"&MAKEpst",
 'pst-labo',	"&MAKEpst",
 'pst-lens',	"&MAKEpst",
 'pst-light3d',	"&MAKEpst",
 'pst-math',	"&MAKEpst",
 'pst-optexp',	"&MAKEpst",
 'pst-ob3d',	"&MAKEpst",
 'pst-optic',	"&MAKEpst",
 'pst-osci',	"&MAKEpst",
 'pst-pad',	"&MAKEpst",
 'pst-pdgr',	"&MAKEpst",
 'pst-poly',	"&MAKEpst",
 'pst-qtree',	"&MAKEpst",
 'pst-slpe',	"&MAKEpst",
 'pst-solides3d',"&MAKEpst",
 'pst-soroban',	"&MAKEpst",
 'pst-spectra',	"&MAKEpst",
 'pst-stru',	"&MAKEpst",
 'pst-text',	"&MAKEpst",
 'pst-uml',	"&MAKEpst",
 'pst-vue3d',	"&MAKEpst",
 'pstricks',	"&MAKEpstricks",
 'pstricks-add',"&MAKEpst",
 'pxfonts',	"&MAKEflatten",
 'realcalc',	"die 'skipping, nosell license'",
 'references',	"die 'skipping, requires binary'",
 'refstyle',	"&MAKEcopy",
 'revtex',	"&MAKEflatten",
 'sae',		"die 'skipping, nosell license'",
 'seminar',	"&MAKEseminar",
 'shipunov',	"&MAKEcopy",
 'shortlst',	"die 'skipping, nosell license'",
 'showexpl',	"&MAKEflatten",
 'siam',	"&MAKEsiam",
 'skak',	"&MAKEflatten",
 'slidenotes',	"die 'skipping, nonfree'",
 'songs',	"die 'skipping, requires binary'",
 'staves',	"&MAKEflatten",
 'stellenbosch',"&MAKEcopy",
 'stex',	"&MAKEflatten",
 'symbolindex',	"die 'skipping, requires binary'",
 't2',		"&MAKEt2",
 'tamethebeast',"&MAKEtamethebeast",
 'tamil-omega',	"die 'skipping, supports nonfree ISM fonts'", #"&MAKEflatten",
 'taylor',	"die 'skipping, nonfree license'",
 'template',    "die 'already part of xpackages'",
 'tengwarscript',"&MAKEflatten",
 'tex-gyre',	"&MAKEcopy",
 'tex-refs',	"die 'skipping, needs work'",
 'texdraw',	"&MAKEtexdraw",
 'texpower',	"&MAKEnosymlinks",
 'texsis',	"&MAKEtexsis",
 'thaifonts-scalable',	"die 'Thai, fontforge format only, skip'",
 'thailatex',	"die 'Thai, requires preprocessor (?), skip'",
 'thsmc',	"die 'skipping, requires nonfree font'",
 'ticket',	"&MAKEflatten",
 'tipa',	"&MAKEtipa",
 'titlepage-uni-dortmund', "die 'needs graphics (too short names) in .'",
 'tpcmfont',	"die 'skipping, ?'",
 'translator',	"&MAKEflatten",
 'turnstile',	"&MAKEflatten",
 'txfonts',	"&MAKEflatten",
 'ucs',		"&MAKEucs",
 'uebungsblatt',"&MAKEflatten",
 'ukrhyph',	"&MAKEukrhyph",
 'unitsdef',	"&MAKEflatten",
 'velthuis',	"&MAKEcopy",
 'venturisadf',	"die 'skipping, no tfm/etc. support'",
 'verbatimcopy',"die 'skipping, no doc source'",
 'vhistory',	"&MAKEflatten",
 'vicentino',	"die 'skipping, nonfree license'",
 'voss-de',	"&MAKEvossde",
 'vrsion',	"die 'skipping, nonfree license'",
 'wadalab',     "&MAKEwadalab",
 'wasy2',	"&MAKEflatten",
 'wntamil',	"die 'skipping, nonfree license'",
 'wordcount',	"&MAKEwordcount",
 'xbase',       "die 'renamed to xpackages'",
 'xecjk',	"&MAKEcopy",
 'xecyr',	"&MAKEcopy",
 'xepersian',	"&MAKEflatten",
 'xetex-pstricks',"&MAKEcopy",
 'xfrac',	"die 'skipping, still experimental'", #&MAKEflatten",
 'xinitials',   "die 'will be in xpackages when ready (Morten says)'",
 'xkeyval',	"&MAKExkeyval",
 'xmltex',	"&MAKExmltex",
 'xor',         "die 'will be in xpackages when ready (Morten says)'",
 'xparse',      "die 'already in xpackages'",
 'xtheorem',    "die 'will be in xpackages when ready (Morten says)'",
 'xymtex',	"&MAKExymtex",
 'xypic',	"&MAKExypic",
 'zefonts',	"&MAKEflatten",
 'zwgetfdate',  "&MAKEcopy",
);


%flatten_prehook = (
 'cm-super'		=> '&FLATTEN_PREHOOK_cm_super',
 'ibygrk'		=> '&FLATTEN_PREHOOK_ibygrk',
);

%specialpostaction = (
 'bibleref'             => '&POSTlatex2html',
 'datetime'             => '&POSTlatex2html',
 'doipubmed'            => '&POSTlatex2html',
 'fpl'			=> '&POSTfpl',
 'glossaries'		=> '&POSTglossaries',
 'ibygrk'		=> '&POSTibygrk',
 'impatient'		=> '&POSTimpatient',
 'interactiveworkbook'	=> '&POSTinteractiveworkbook',
 'knuth'		=> '&POSTknuth',
 'koma-script'          => '&POSTkoma',
 'libertine'		=> '&POSTlibertine',
 'pgf'			=> '&POSTpgf',
 'pst-cox'		=> '&POSTpstcox',
 'xecjk'		=> '&POSTxecjk',
 'xecyr'		=> '&POSTxecyr',
 'xetex-pstricks'	=> '&POSTxetex_pstricks',
);


# needs special TeX program to run the doc.
%specialTEX = (
 'arabtex',	'tex',
 'barr',	'latex',
 'beamer',	'pdflatex',
 'bytefield',	'pdflatex',
 'esint-type1',	'pdftex',
 'euro-ce',	'tex',
 'floatrow',	'latex',
 'genealogy',	'tex',
 'insbox',	'tex',
 'iso10303',	'pdflatex',
 'mfpic',	'tex',
 'mpattern',	'true',	# requires running mpp, but it's not executable and
                     # anyway it's just a test file.  ignore it.
 'ofs',		'csplain',
 'pdfscreen',	'pdflatex',
 'pdfslide',	'pdflatex',
 'pl-qx',	'platex',
 'subfig',	'pdflatex',
 'texsis',	'tex',
 'typespec',	'tex',
 'wasy2',	'tex',
 'webeq',	'pdflatex',
);


$standardsource='\.fdd|\.dtx|\.ins|\.c$|Makefile|configure.*|install-sh|\.drv';
%specialsource= (
 'FAQ-en',		'NULL',
 'ae',			"$standardsource|\.mtx|\.etx|\.tex|clean|go|install|makepl",
 'amsldoc-vn',		'NULL',
 'apl',			".*",    # just get everything, seems simplest
 'arabxetex',		'NULL',  # keep dtx with others, why not
 'bbold',		"$standardsource|fonttabl.sty",
 'blacklettert1',	'\.dtx|\.ins|\.pl|Makefile',
 'carlisle',		'\.dtx|\.ins|ltxtable\.tex',
 'epsf',		'NULL',
 'epslatex-fr',		'NULL',
 'eskdx',		'NULL',  # do not move makefiles
 'feynmf',		"$standardsource|feynmf\.pl",
 'mff',			'\.mfj|\.bat|\.diz',
 'fpl',			"$standardsource|Add|\.sfd|\.pe|\.ps",
 'hyphenex',		".*",
 'impatient',		'NULL',	# doc package
 'latex2e-help-texinfo','NULL',	# doc package
 'mpman-ru',		'NULL',	# doc package
 'patch',		'\.doc',
 'pgfplots',		'NULL',	# keep manual.install.tex in doc/
 'rcs',			"$standardsource|rcs.el|src",
);

%specialfoundry = (
 'fc',		'jknappen',
 'mfpic',	'metafont',
);
$standardfoundry='public';


%specialdest = (
 'MemoirChapStyles',	'texmf-doc',
 'Type1fonts',		'texmf-doc',
 'a2ping',		'texmf',
 'amsldoc-it',		'texmf-doc',
 'amsldoc-vn',		'texmf-doc',
 'amsthdoc-it',		'texmf-doc',
 'beamer-tut-pt',	'texmf-doc',
 'catalogue',		'texmf-doc',
 'comprehensive',	'texmf-doc',
 'cursolatex',		'texmf-doc',
 'dtxtut',		'texmf-doc',
 'elhyphen',		'texmf',
 'epslatex-fr',		'texmf-doc',
 'epstopdf',		'texmf',
 'es-tex-faq',		'texmf-doc',
 'free-math-font-survey', 'texmf-doc',
 'hyphenex',		'texmf-dist',
 'knuth',		'texmf-doc',
 'l2picfaq',		'texmf-doc',
 'l2tabu-english',	'texmf-doc',
 'lshort-bulgarian',	'texmf-doc',
 'lshort-english',	'texmf-doc',
 'lshort-finnish',	'texmf-doc',
 'lshort-portuguese',	'texmf-doc',
 'lshort-turkish',	'texmf-doc',
 'lshort-vietnamese',	'texmf-doc',
 'lshort-korean',	'texmf-doc',
 'makingtexwork',	'texmf-doc',
 'mathmode',		'texmf-doc',
 'mnhyphn',		'texmf',
 'ntheorem-vn',		'texmf-doc',
 'tamethebeast',	'texmf-doc',
 'tds',			'texmf-doc',
 'tex-refs',		'texmf-doc',
 'visualfaq',		'texmf-doc',
 'voss-de',		'texmf-doc',
 'xypic-tut-pt',	'texmf-doc',
 'wp-conv',		'texmf-doc',
 'xetexref',		'texmf-doc',
);
$standarddest = "texmf-dist";

# 
%specialsourcefmt = (
 'antomega',	'omega',
 'apl',		'fonts',
 'arabxetex',	'xelatex',
 'archaic',	'fonts',
 'arev',	'fonts',
 'arrayjob',	'generic',
 'bidi',	'xelatex',
 'blacklettert1','fonts',
 'blockdraw_mp','metapost',
 'cb',		'fonts',
 'cirth',	'fonts',
 'cirth',	'generic',
 'cjhebrew',	'fonts',
 'cmpica',	'fonts',
 'cryst',	'fonts',
 'eplain',	'eplain',
 'epsf',	'generic',
 'eurosym',	'fonts',
 'expressg',	'metapost',
 'fc',		'fonts',
 'fge',		'fonts',
 'fltpoint',	'generic',
 'fourier',	'fonts',
 'fouriernc',	'fonts',
 'fpl',		'fonts',
 'frcursive',	'fonts',
 'genmisc',	'generic',
 'germbib',	'bibtex',
 'gost',	'bibtex',
 'greenpoint',	'fonts',
 'hfoldsty',	'fonts',
 'hyphenex',	'generic',
 'kixfont',	'fonts',
 'latexmp',	'metapost',
 'leawood',	'fonts',
 'lfb',		'fonts',
 'latexmp',	'metapost',
 'mathdots',	'generic',
 'mkjobtexmf',	'generic',
 'mnhyphn',	'generic',
 'mfpic',	'generic',
 'multido',	'generic',
 'ofs',		'generic',
 'patch',	'generic',
 'pdcmac',	'plain',
 'philokalia',	'xelatex',
 'pictex',	'generic',
 'pstricks',	'generic',
 'ruhyphen',	'generic',
 'skaknew',	'metapost',
 'splines',	'metapost',
 'trajan',	'fonts',
 'variations',	'generic',
 'velthuis',	'fonts',
 'wasy2',	'fonts',
 'xltxtra',	'xelatex',
);
$standardsourcefmt='latex';


%specialfmt = (
 'abbr',	'generic',
 'abstyles',	'generic',
 'antomega',	'omega',
 'arabxetex',	'xelatex',
 'arrayjob',	'generic',
 'barr',	'generic',
 'bghyphen',	'generic',
 'bidi',	'xelatex',
 'cirth',	'generic',
 'dehyph-exptl','generic',
 'edmac',	'generic',
 'eijkhout',	'generic',
 'eplain',	'eplain',
 'epsf',	'generic',
 'esint-type1',	'plain',
 'fenixpar',	'generic',
 'fltpoint',	'generic',
 'fontch',	'plain',
 'genmisc',	'generic',
 'hyplain',	'plain',
 'ibygrk',	'generic',
 'ifxetex',	'generic',
 'jadetex',	'jadetex',
 'mathdots',	'generic',
 'metatex',	'plain',
 'mfpic',	'generic',
 'midnight',	'generic',
 'mkpattern',	'plain',
 'ocherokee',	'lambda',
 'ofs',		'generic',
 'passivetex',	'xmltex',
 'pdcmac',	'plain',
 'pdf-trans',	'generic',
 'philokalia',	'xelatex',
 'pictex',	'generic',
 'plnfss',	'plain',
 'pstricks',	'generic',
 'pst-cox',	'generic',
 'ruhyphen',	'generic',
 'shapepar',	'generic',
 'texsis',	'texsis',
 'tugboat-plain','plain',
 'variations',	'generic',
 'vertex',	'plain',
 'wasy2',	'plain',
 'xetex-def',	'xelatex',
 'xetexfontinfo','xetex',
 'xltxtra',	'xelatex',
 'xmlplay',	'xmltex',
 'xunicode',	'xelatex',
);
$standardfmt='latex';


%specialdocfmt = (
 'abbr',	'generic',
 'abstyles',	'bibtex',
 'amsldoc-it',	'italian',
 'amsldoc-vn',	'vietnamese',
 'amsthdoc-it',	'italian',
 'antomega',	'omega',
 'arabxetex',	'xelatex',
 'archaic',	'fonts',
 'arev',	'fonts',
 'arrayjob',	'generic',
 'aurical',	'fonts',
 'automata',	'metapost',
 'ascii',	'fonts',
 'barr',	'generic',
 'bbm',		'fonts',
 'beamer-tut-pt','portuguese',
 'bera',	'fonts',
 'bghyphen',	'generic',
 'bibhtml',	'bibtex',
 'bidi',	'xelatex',
 'blacklettert1','fonts',
 'cbfonts',	'fonts',
 'cirth',	'fonts',
 'cjhebrew',	'fonts',
 'cm-super',	'fonts',
 'cmarrows',	'metapost',
 'cursolatex',	'portuguese',
 'dehyph-exptl','generic',
 'devanagr',	'fonts',
 'dictsym',	'fonts',
 'dinat',	'bibtex',
 'doublestroke','fonts',
 'economic',	'bibtex',
 'edmac',	'generic',
 'elhyphen',	'generic',
 'elsevier-bib','bibtex',
 'encxvlna',    'generic',
 'eplain',	'eplain',
 'epsf',	'generic',
 'epslatex-fr',	'french',
 'es-tex-faq',	'spanish',
 'eurosym',	'fonts',
 'expressg',	'metapost',
 'exteps',	'metapost',
 'fc',		'fonts',
 'featpost',	'metapost',
 'fenixpar',	'generic',
 'fge',		'fonts',
 'fltpoint',	'generic',
 'fontch',	'plain',
 'fourier',	'fonts',
 'fouriernc',	'fonts',
 'fpl',		'fonts',
 'frcursive',	'fonts',
 'genmisc',	'generic',
 'germbib',	'bibtex',
 'gost',	'bibtex',
 'greepoint',	'fonts',
 'hfoldsty',	'fonts',
 'hieroglf',	'fonts',
 'hyplain',	'plain',
 'ibygrk',	'fonts',
 'ifxetex',	'generic',
 'ijqc',	'bibtex',
 'impatient-fr','french',
 'iopart-num',	'bibtex',
 'kixfont',	'fonts',
 'l2picfaq',	'german',
 'l2tabu-spanish',	'spanish',
 'latexmp',	'metapost',
 'leawood',	'fonts',
 'lfb',		'fonts',
 'lnotes',	'chinese',
 'lshort-portuguese',	'portuguese',
 'lshort-spanish',	'spanish',
 'mathdots',	'generic',
 'metatex',	'plain',
 'metauml',	'metapost',
 'mfpic',	'generic',
 'midnight',	'generic',
 'mkpattern',	'plain',
 'mkjobtexmf',	'generic',
 'mpattern',	'metapost',
 'mpman-ru',	'russian',
 'ntheorem-vn',	'vietnamese',
 'ofs',		'generic',
 'pacioli',	'fonts',
 'pdcmac',	'plain',
 'pdf-trans',	'generic',
 'pdfcrop',	'support',
 'phaistos',	'fonts',
 'philokalia',	'xelatex',
 'pictex',	'generic',
 'plnfss',	'plain',
 'psfrag-italian',	'italian',
 'pst-cox',		'generic',
 'pxfonts',	'fonts',
 'shapepar',	'generic',
 'skak',	'latex',
 'splines',	'metapost',
 'staves',	'fonts',
 'tamil-omega',	'omega',
 'templates-fenn',	'german',
 'templates-sommer',	'german',
 'texcount',	'support',
 'texsis',	'texsis',
 'textpath',	'metapost',
 'trajan',	'fonts',
 'tugboat-plain','plain',
 'txfonts',	'fonts',
 'vancouver',	'bibtex',
 'variations',	'generic',
 'velthuis',	'generic',
 'vertex',	'plain',
 'voss-de',	'german',
 'wasy2',	'fonts',
 'xetexfontinfo','xetex',
 'xltxtra',	'xelatex',
 'xq',		'fonts',
 'xunicode',	'xelatex',
 'xypic-tut-pt','portuguese',
);
$standarddocfmt='latex';


# special cases of which .ins files to run; used to remove
# normal choices, and get the most general.
%specialins = (
 'aastex',	'NULL',  # everything is pregenerated
 'base',	'NULL',
 'bbold',	'bbold.dtx',
 'blacklettert1','NULL',  # don't try to do fontinst
 'bosisio',	'.*\.dtx',
 'carlisle',	'\.ins|ltxtable.tex',
 'ccfonts',	'ccfonts.ins',
 'dotseqn',	'dotseqn.dtx',
 'feynmf',	'feynmf.ins',
 'floatrow',	'floatrow.ins',
 'lettre',	'NULL',
 'localloc',	'localloc.dtx',
 'makecell',	'makecell.dtx',
 'namespc',	'namespc.dtx',
 'paper',	'install',
 'parrun',	'parrun.ins',
 'stmaryrd',	'stmaryrd.dtx',
 'tablists',	'tablists.dtx',
 'thesis',	'install.01|install.ndx',
 'turnstile',	'turnstile-en.ins', # skip pt
);
$standardins='\.ins';

%specialinsrunner = (
 'bullcntr',	'latex',  # requires interaction
 'ctable',	'latex',  # requires interaction
 'polski',	'latex',  # requires interaction
 'psfragx',	'latex',  # requires interaction
);
$standardinsrunner="latex -interaction=nonstopmode";

%specialmakeindex= (
 'mpman-ru'	=> 'NULL',	# doc
);
$standardmakeindex='\.ist';


# packages which need special .tex/.sty files installed
$standardtex='\.cfg|\.sty|\.clo|\.ldf|\.cls|\.def|\.fd$|\.cmap|\.4ht$';
%specialtex= (
 'FAQ-en',	'NULL',
 'abbr',	'\.tex',
 'abstyles',	'apreambl.tex',	# not a4c.sty
 'ae',		'\.fd$|\.sty', 
 'apa',		'\.apa|\.cls',	# not endfloat.cfg
 'apacite',	'\.apc|' . $standardtex,
 'arabtex',	'\.tex|' . $standardtex,
 'babelbib',	'\.bdf|\.sty',
 'bangtex',	'bangfont\.tex|' . $standardtex,
 'bardiag',	'\.bar|\.sty|\.cfg',
 'barr',	'diagxy.tex',
 'base',	'idx.tex|lablst.tex|latexbug.tex|lablst.tex|docstrip.tex|nfssfont.tex|sample2e.tex|small2e.tex|testpage.tex|ltxcheck.tex|\.cfg|\.fd$|\.cls|\.clo|\.ltx|\.sty|\.def|^\.',
 'bbold',	'bbold.sty|\.fd',	# no fonttabl.sty
 'bghyphen',	'\.tex',
 'blockdraw_mp','NULL',		    	# skip .sty's
 'breqn',	'\.sty|\.sym',
 'calxxxx',	'cal.*\.tex',
 'captcont',	'\.sty|[^c]\.cfg',	# omit ltxdoc.cfg, would be system-wide
 'carlisle',	'\.sty|\.ltx',
 'chemstyle',	'\.jdf|' . $standardtex,
 'cirth',	'num\.tex',
 'clock',	'\.sty|clock\.tex',
 'cmap',	'\.cmap|' . $standardtex,
 'codepage',	'\.sty|\.tex',
 'contour',	'\.cfg|\.sty|\.cnt',
 'ctib',	'\.sty|\.clo|\.ldf|\.cls|\.def|\.fd$|ctib\.tex',
 'custbib',	'\.mbs|\.tex',
 'custom-bib',	'\.mbs|\.tex',
 'cyrillic',	'\.tex|\.sty|\.fd$|\.def',
 'dehyph-exptl','de.*\.tex|\.pat',
 'dialogl',	'\.sty|listouti\.tex',
 'din1505',     'NULL', # no tex files, only natbib.cfg, would be system-wide
 'disser',	'\.rtx|' . $standardtex,
 'dlfltxb',	'\.sty', # no sample.cfg
 'ean',		'ean[0-9]*\.tex',
 'easy',	'easy.*\.sty',		# no mydoc.sty
 'ecv',		'\.sty|\.cls|\.ldf',	# no docstrip.cfg, else system-wide
 'edmac',	'edmac.tex|edstanza.tex|\.sty',
 'eijkhout',	'\.tex',
 'epsf',	'epsf.(tex|sty)',
 'epslatex-fr',	'NULL',
 'esint-type1',	'esint.tex',
 'europecv',	'EuropeFlag|europasslogo|\.cls|\.def',
 'fltpoint',	'\.sty|\.tex',
 'fontch',	'\.tex',
 'footnpag',	'footnpag\.sty',
 'frankenstein','\.(sto|stq)|' . $standardtex,
 'genmisc',	'\.sty|\.tex',
 'geometry',	'\.sty|\.clo|\.ldf|\.cls|\.def|\.fd$', # not cfg
 'ginpenc',	'\.gie|\.sty',
 'hfoldsty',	'\.sty|\.fd|\.cpa',
 'hyper',	'\.sty|\.hyp',
 'hyplain',	'(hyrules|hy.*plain|hylang)\..*',
 'ibygrk',	'iby4extr.tex|ibycus4.tex|ibycusps.tex|pssetiby.tex|setiby4.tex|tlgsqq.tex|version4.tex|' . $standardtex,
 'insbox',	'insbox.tex',
 'interactiveworkbook',	'NULL', # done in POSTinteractiveworkbook
 'iso10303',	'a.*tex|b.*tex|e.*tex|stp.*tex|\.sty|\.4ht',
 'isodate',	'\.idf|\.sty',
 'isodoc',	'iso.*\.sty',  # not mystyle.sty, etc.
 'jadetex',	'\.ltx|\.def|\.tex|\.ini|\.sty',
 'karnaugh',	'kvmacros.tex',
 'kastrup',     'binhex.tex|' . $standardtex,
 'keystroke',	'keystroke_.*|\.sty',
 'kuvio',	'\.tex|\.sty',
 'latex-course','NULL',  # keep doc together
 'lettre',	'\.ins|\.cls',
 'manjutex',	'\.sty|\.clo|\.ldf|\.cls|\.def|\.fd$|manju.tex',
 'mathdots',	'mathdots\.tex|' . $standardtex,
 'metatex',	'metatex.tex',
 'mff',		'\.sty|mf[^f].*\.tex',
 'mfpic',	'mfpic.tex|mfpic.sty|mfppatch.tex',
 'midnight',	'\.tex',
 'mathdots',	'\.mld|' . $standardtex,
 'misc',	'\.sty|\.ltx|\.cls',
 'mkpattern',	'mkpatter.tex',
 'mpman-ru',	'NULL',		# doc package
 'msg',		"-msg\.tex" . $standardtex,
 'nag',		'\.nag|' . $standardtex,
 'nddiss',	'\.sty|\.clo|\.ldf|\.cls|\.def|\.fd$',
 'ntheorem',	'\.sty|\.std',
 'ofs',		'^ofs\.tex|ofsdef\.tex|ofs-.*\.tex|\.sty|a.*\.tex|.*fn\.tex',
 'patch',	'\.tex',
 'pdf-trans',	'pdf-trans.tex',
 'pdfcprot',	'\.cpa|\.sty',
 'pdfscreen',	'overlay.*pdf|but.*pdf|left.*pdf|right\.pdf|pdfscreen.sty',
 'pdfslide',	'\.jpg|\.sty|\.clo|\.cfg|meta.*\.pdf',
 'petri-nets',	'pnets\.tex|pntext\.tex|\.sty|pndraw\.tex|pnversion\.tex|\.sty|pndraw\.tex',
 'pictex',	'\.sty|\.tex',
 'plgraph',	'\.tex',
 'plnfss',	'\.tex|\.pfd',
 'powerdot',	'\.ps|' . $standardtex,
 'ppchtex',	'm.*tex|m.*sty',
 'prosper',	'\.ps|\.eps|\.sty|\.cls',
 'pstricks',	'pst-*\.tex',
 'pst-cox',	'pst-cox(coor|eterp)\.tex',
 'pst-geo',	'pst-map.*\.tex|pst-map.*\.sty',
 'pst-infixplot', 'infix-RPN\.tex|pst-infixplot\.tex',
 'qobitree',	'qobitree.tex',
 'r_und_s',	'\.tex|\.sty',
 'realcalc',	'realcalc.tex',
 'revtex',	'\.sty|\.cls|\.rtx',
 'rlepsf',	'rlepsf.tex',
 'seminar',	'\.bug|\.bg2|\.cls|\.sty|2up.tex',
 'shapepar',	'\.sty',  # not def
 'showexpl',	'\.sty|\.clo|\.ldf|\.cls|\.def|\.fd$',  # not cfg
 'splitindex',	'splitindex\.tex|' . $standardtex,
 'spotcolor',	'spotcolor*.tex',
 'startex',	'\.tex',
 'subfig',	'\.sty|[^c]\.cfg',  # omit ltxdoc.cfg, would be system-wide
 'subfigure',	'\.sty|[^c]\.cfg',  # omit ltxdoc.cfg, would be system-wide
 'syntax',	'syntax\.tex',
 'taylor',	'diagrams.tex',
 'texsis',	'\.txs|TXS.*tex|texsis.tex',
 'ticket',	'\.tdf|' . $standardtex,
 'tools',	'\.cfg|\.sty|\.clo|\.cls|\.def|\.fd$|.?\.tex|^\.tex$',
 'translator',	'\.dict|translator-language-mappings.tex|' . $standardtex,
 'tugboat-plain','\.cmn|' . $standardtex,
 'variations',	'^variations\.tex|' . $standardtex,  # not docvariations.tex
 'vertex',	'vertex\.tex|' . $standardtex,
 'vhistory',	'\.sty', # not hyperref.cfg
 'wasy2',	'wasyfont\.tex',
 'wordcount',	'\.tex',
 'xetexfontinfo','\.tex',
 'zefonts',	'\.sty|\.fd',
);


# packages which need special documentation files run
%oldspecialdvi= (
 'barcode2',	'eandoc.tex',
 'bardiag',	'bar.*tex',
 'base',	'.*info.tex|.*guide.*tex|.*news.*tex',
 'blacklettert1','\.dtx',
 'calendar',	'demo.*\.tex|calguide\.tex',
 'carlisle',	'\.dtx|ltxtable.tex',
 'chess',	'\.ltx',
 'circ',	'\.dtx',
 'cirth',	'cirth\.tex',
 'codepage',	'codepage\.drv',
 'crop',	'crop.dtx',
 'ctib',	'ctib4tex.tex',
 'custbib',	'\.dtx',
 'custom-bib',	'\.dtx',
 'dialogl',	'dia-driv\.tex|codialog\.tex',
 'directory',	'\.tex',
 'eepic',	'eepic.tex',
 'ethiop',	'ethiodoc\.tex',
 'euro',	'euro.dtx',
 'fancynum',	'examples.tex',
 'fp',		'example.tex',
 'frcursive',	'.*\.dtx',
 'gatech-thesis', 'gatech-thesis.tex|jules-verne.tex',
 'german',	'germdoc\.tex',
 'insbox',	'demo.tex',
 'isostds',	'isosty.tex',
 'jurabib',	'jbtest.tex',
 'karnaugh',	'kvdoc\.tex',
 'manjutex',	'manjutex.tex',
 'mapcodes',	'mapcode\.drv',
 'mff',		'mffdoc.tex',
 'minutes',	'Sample.tex',
 'ofs',		'ofsdoc-e\.tex|ofsdoc\.tex|ofs-slt\.tex',
 'ogonek',	'togonek\.ltx|\.tex',
 'ot2cyr',	'OT2.*tex',
 'othello',	'othello\.tex',
 'paper',	'paper.drv',
 'parrun',	'parrun.dtx',
 'petri-nets',	'pndoc\.tex',
 'prosper',	'pros.*tex',
 'pst-3dplot',	'.*-e\.tex|doc-.*.tex|pst-3dplot-doc',
 'pst-bar',	'.*-e\.tex|doc-.*.tex|pst-bar-doc.tex',
 'pst-blur',	'.*-e\.tex|doc-.*.tex|pst-blur-doc.tex',
 'pst-circ',	'.*-e\.tex|doc-.*.tex|pst-circ-doc.tex',
 'pst-fr3d',	'doc-.*.tex|pst-fr3d-doc',
 'pst-func',	'.*-e\.tex|doc-.*.tex|pst-func-doc',
 'pst-geo',	'.*-e\.tex|doc-.*.tex|pst-geo-doc.tex',
 'pst-ghsb',	'.*-e\.tex|doc-.*.tex|pst-ghsb-doc.tex',
 'pst-gr3d',	'.*-e\.tex|doc-.*.tex|pst-gr3d-doc.tex',
 'pst-jftree',	'.*-e\.tex|doc-.*.tex|pst-jftree-doc.tex',
 'pst-lens',	'.*-e\.tex|doc-.*.tex|pst-lens-doc.tex',
 'pst-light3d',	'.*-e\.tex|doc-.*.tex|pst-light3d-doc',
 'pst-math',	'.*-e\.tex|doc-.*.tex|pst-math-doc.tex',
 'pst-optic',	'.*-e\.tex|doc-.*.tex|pst-optic-doc.tex',
 'pst-osci',	'.*-e\.tex|doc-.*.tex|pst-osci-doc.tex',
 'pst-poly',	'.*-e\.tex|doc-.*.tex|pst-poly-doc.tex',
 'pst-slpe',	'.*-e\.tex|doc-.*.tex|pst-slpe-doc.tex',
 'pst-uml',	'.*-e\.tex|doc[-_].*.tex|pst-uml-doc.tex',
 'pst-vue3d',	'.*-e\.tex|doc-.*.tex|pst-vue3d-doc.tex',
 'qobitree',	'example\.tex',
 'rcsinfo',	'rcsinfo2html.tex',
 'refman',	'layout.tex|\.dtx',
 'soul',	'soul.dtx',
 'syntax',	'syntax[a-z].*\.tex',
 'texsis',	'Manual.tex',
 'textmerg',	'tmexamp[[0-9]\.tex',
 'thesis',	'\.drv',
 'timing',	'timing.tex',
 'tipa',	'tipaman\.tex|tipatug\.tex',
 'tools',	'\.dtx',
 'umrand',	'umrand\.tex',
 'ulsy',	'\.dtx',
 'velthuis',	'manual.tex',
 'wasy2',	'wasydoc\.tex',
 'xymtex',	'xymtx200.tex',
 'zefonts',	'zefonts.tex',
);

#$standarddvi='\.tex|\.ltx'; 
%specialdvi = ();
$standarddvi = 'NULL';  # rely on authors/CTAN making pdf's.


# packages which need special MetaPost files
$standardmp = '\.mp$';
%specialmp = (
 'automata',	'automata.mp',	# skip example.mp
 'bpolynomial',	'bpolynomial.mp', # skip examples.mp
 'dviincl',	'fix.*mp',	# skip test-bop.mp
 'epsincl',	'eps.*mp',	# skip testincl.mp
 'feynmp',	'feynmp.mp',
 'latexmp',	'latexmp.mp',
 'mpattern',	'mpattern.mp',	# don't install test.mp
 'mpman-ru',	'NULL',		# doc package
 'polski',	'NULL',		# no sample-*.mp
 'semioneside', 'NULL',		# don't install figure*.mp
 'textpath',    'textpath.mp',	# don't install textpathfigs.mp
);

# packages which need special BibTeX styles installed
%specialcsf= ();
$standardcsf='\.csf';

$standardbst='\.bst';
%specialbst= (
 'umthesis',	'NULL',
);

# packages which need special BibTeX data files (not) installed.
$standardbib='\.bib$'; # $ so we don't find README.bibtex in IEEEtran
%specialbib= (
 'acmconf',	'NULL',
 'aguplus',	'NULL',
 'amsrefs',	'ams.*bib', # not jr.bib
 'apa',		'NULL',
 'babelbib',	'NULL',
 'classicthesis','NULL',
 'dehyph-exptl','NULL',
 'dlfltxb',	'NULL', # don't install doc.
 'doipubmed',	'NULL',
 'economic',	'NULL',
 'eplain',	'NULL',
 'epslatex-fr',	'NULL',
 'gcite',	'NULL',  # bib is for doc
 'germbib',	'NULL',  # no second xampl.bib, test bibs, etc.
 'ijqc',	'NULL',
 'imtekda',	'NULL',
 'iopart-num',	'NULL',
 'jurarsp',	'NULL',
 'mslapa',	'NULL',
 'munich',	'NULL',
 'pgfplots',	'NULL',  # no manual.bib
 'pgf-soroban',	'NULL',
 'pst-labo',	'NULL',
 'si',		'NULL',
 'ucthesis',	'NULL',
 'umthesis',	'NULL',
 'uwthesis',	'NULL',
);

# packages which have Metafont sources to run.
$standardmf='[0-9]\.mf';
%specialmf= (
 'astro',	'astrosym.mf',
 'backgammon',	'bg\.mf',
 'cherokee',	'cherokee.mf',
 'circ',	'csybimos\.mf|csycirc\.mf|csydiod\.mf|csyrest\.mf|csywidko\.mf|csysym\.mf|optic\.mf',
 'cirth',	'cir.*\.mf',
 'clock',	'clock.mf',
 'cmcyr',	'NULL', # already made
 'cmpica',	'cmpic.*\.mf',
 'dancers',	'dancers\.mf',
 'dice',	'dice3d\.mf',
 'dingbat',	'\.mf',
 'eiad',	'e.*10\.mf',
 'engwar',	'engwar\.mf',
 'euro-ce',	'eu.*\.mf|ce.*\.mf',
 'feynmf',	'feynmf\.mf',
 'greenpoint',	'greenpoint\.mf',
 'hands',	'hands\.mf',
 'ibygrk',	'NULL',
 'ifsym',	'\.mf|\.gen',
 'logic',	'milstd\.mf',
 'mfpic',	'grafbase\.mf',
 'morse',	'morse10.mf|morse.def',
 'ogham',	'ogham\.mf',
 'skak',	'skak.*[0-9].*\.mf',
 'tengwar',	'tengwar\.mf',
 'umrand',	'umrand[ab]\.mf',
 'xq',		'xq(normal|large)\.mf',
);

# additional mf files to be installed but not run.
%specialmfinstall = (
 'astro'	=> 'astrosym.(cal|cmn|mac|uni|xtr)',
 'cmcyr'	=> '\.mf',	
 'ibygrk'	=> 'ibycus4\.map',	# tex|mf source
);

# packages which have dvips header files
$standardpro='\.pro$';
%specialpro= (
 'cm-super',	'config.cm-super|cm-super.GS',
 'dvipsconfig',	'.*',  # addpsctrl should be in bin, but ...
 'esint-type1',	'config.esint',
 'initials',	'config.*',
 'pspicture',	'pspicture.ps',
 'zefonts',	'slantcm.cfg',
);

$standardmap='\.map';
%specialmap = (
 'arabxetex'	=> '\.(map|tec)$',
 'kerntest'	=> 'NULL',	# skip test map file
 'ibygrk'	=> 'iby\.map',	# not ibycus4.map, which is tex|mf
);
$standardmapdest = "fonts/map/dvips";
%specialmapdest = (
  'arabxetex' => "fonts/misc/xetex/fontmapping",
);

$standardvmap='\.ali$';

$standardenc='\.enc';

$standardafm='\.afm';
%specialafm= ();

$standardpfm='\.pfm';
%specialpfm= ();

$standardpfb = '\.pfb|\.inf$';
%specialpfb = (
 'dviincl'	=> 'NULL',	# skip 0dviincl.inf, is a README
);

$standardttf='\.ttf';
%specialttf= ();

$standardotf='\.otf';
%specialotf= ();

$standardovf='\.ovf';
%specialovf= ();

$standardofm='\.ofm';
%specialofm= ();

$standardovp='\.ovp';
%specialovp= ( 'psfragx',	'NULL',	);

$standardotp='\.otp';
%specialotp= ();

$standardocp='\.ocp';
%specialocp= ();

# packages which have xmltex files
%specialxmt= (
  # 'passivetex',	'\.xmt|fotex.sty',
);
$standardxmt='\.xmt';

# packages which have executable scripts
%specialscripts = (
 'a2ping'	=> '\.pl$',
 'dviasm'	=> '\.py$',
 'epstopdf'	=> 'epstopdf',
 'mkjobtexmf'	=> '\.pl$',
 'pdfcrop'	=> '\.pl$',
 'perltex'	=> '\.pl$',
 'pst2pdf'	=> '\.pl$',
 'texcount'	=> '\.pl$',
 'vpe'		=> '\.pl$',
);

# too painful to install in multiple trees just now.
## packages which have man pages to install.  Assume section 1 for now.
#%specialmans = (
# 'mkjobtexmf'	=> 'mkjobtexmf.man',
#);


# which suffixes to remove after building.  Checked after runins and at
# the end, in the doc directory.
$standardclean = '\.head|\.tmp|\.dvi|\.log|\.out|\.aux|\.toc|\.lof|\.lot'
                . '|\.bbl|\.blg|\.idx|\.ind|\.ilg|\.glo|\.gls|\.loa';
%specialclean  = (
 'a2ping'	=> 'README',  		# not worth whole separate doc subdir
 'achemso'	=> "$standardclean|jawltxdoc.sty",	# temp file for doc
 'acmconf'	=> "$standardclean|flushend.sty",	# dup with sttools
 'chemscheme'	=> "$standardclean|jawltxdoc.sty",	# temp file for doc
 'chemstyle'	=> "$standardclean|jawltxdoc.sty",	# temp file for doc
 'gentle'	=> 'gentle.ps.gz',	# pdf is enough
 'hyph-utf8'	=> 'README',
 'latex2e-help-texinfo' => '\.info',	# must move .info by hand, sigh
 'lshort-spanish'=>'lshort-a5book.pdf',	# a4 is enough
 'mathexam'	=> 'sample.tex~',
 'notes2bib'	=> "$standardclean|jawltxdoc.sty",	# temp file for doc
 'rsc'		=> "$standardclean|jawltxdoc.sty",	# temp file for doc
);

# if a hash entry is specified here, README.TEXLIVE is created mentioning
# that the files were removed.  These are checked after runins.
%moreclean = (
 'AkkTeX'	=> 'still to do, sorry',
 'FAQ-en'	=> 'letterfaq\.pdf',
 'bbcard'	=> 'bbcard.tpm',
 'chessboard'	=> 'chessboard.pdf',
 'chessfss'	=> 'chessfonts_gallery.pdf|chessfss.pdf',
 'comprehensive'=> 'symbols-letter.pdf',	# a4 is enough
 'dateiliste'   => 'dateiliste.README*',	# already in dist
 'dcpic'	=> '.*\.pdf',			# no source
 'din1505'      => 'leitbild3.pdf|normpatsoft.pdf', # no source
 'ecclesiastic' => 'ecclesiastic-sample.pdf',   # no source
 'ednotes'	=> 'perpage.sty',		# copy from bigfoot
 'elsarticle'	=> 'elsdoc.pdf',		# no source
 'epslatex-fr'	=> 'R?Danger.eps',
 'flacards'	=> 'flacards.pdf',
 'gfsartemisia'	=> 'A*Specimen.pdf',		# nonfree
 'gfsbaskerville'=>'B*Specimen.pdf',		# nonfree
 'gfsbodoni'	=> 'B*Specimen.pdf',		# nonfree
 'gfscomplutum'	=> 'C*Specimen.pdf',		# nonfree
 'gfsdidot'	=> '[DO]*Specimen.pdf',		# nonfree
 'gfsneohellenic'=>'N*Specimen.pdf', 		# nonfree
 'guitbeamer'	=> 'guitbeamer-de.pdf',
 'jknapltx'	=> 'ubbold.fd', # clashes bbold's Ubbold.fd; sauter bbold fails
 'linguex'	=> 'cgloss4e.sty',		# symlink
 'piechartmp'	=> 'piechartmp.pdf',
 'pst-3dplot'	=> 'tb72voss3d.pdf',		# no source
 'ptptex'       => 'overcite.sty|cite.sty|wrapfig.sty', # duplicated
 'stubs'	=> 'stubs.pdf',
 'susy'		=> 'susy.pdf',			# no source
 'xskak'	=> 'xskak.pdf',			# no source
);

# 
# Read from config file to make local adjustments to above.
readconfig();

# command line options
$opt_debug = 1;  # verbosity is good
exit 2 unless Getopt::Long::GetOptions (
  "ctan-dir=s",
  "debug!",
  "help",
  "test|n!",
  "version",
);

for (@ARGV) { 
  $packagedir = $_;
  if (! -d $packagedir) {
    warn "$0: $packagedir not a directory, skipping.\n";
    next;
  }

  &set_dir_defaults ($opt_ctan_dir);

  @x = split(/\//,$packagedir);
  $package = pop (@x);
  $DEST_TREE = $specialdest{$package} || $standarddest;

  $TOPDEST = "$TDS/$package";
  $DEST = "$TOPDEST/$DEST_TREE";

  $insrunner = $specialinsrunner{$package} || $standardinsrunner;

  $whichformat = $specialfmt{$package} || $standardfmt;
  $whichdocformat = $specialdocfmt{$package}
                || ($DEST_TREE eq "texmf-doc" ? "english" : $standarddocfmt);

  print "pkg=$package (fmt=$whichformat docfmt=$whichdocformat) -> $DEST\n";
  if (exists $special{$package}) {
    if ($special{$package} =~ s/^die //) {
      # avoid repeating the die message.
      die "$package failed: $special{$package}\n";
    } else {
      print "special: $special{$package}...\n";
      eval $special{$package};
      die "$package failed in $special{$package}: $@" if $@;
    }
  } else {
    &donormal;
  }

  &xchdir ($startdir);
}



# Override our default guess of "latex" if we can intuit from the CTAN
# path, which ctan2tl kindly passes us.
# 
sub set_dir_defaults
{
  my ($ctan_dir) = @_;
  my $guess = "";
  
  if ($ctan_dir =~ m!/graphics/metapost/!) {
    $standarddocfmt = $standardsourcefmt = "metapost";
    $guess = "$standarddocfmt for docfmt/srcfmt";

  } elsif ($ctan_dir =~ m!/macros/xetex/latex/!) {
    $standarddocfmt = $standardsourcefmt = $standardfmt = "xelatex";
    $guess = "$standarddocfmt for fmt/docfmt/srcfmt";

  } elsif ($ctan_dir =~ m!/macros/plain/!) {
    $standarddocfmt = $standardsourcefmt = $standardfmt = "plain";
    $guess = "$standarddocfmt for fmt/docfmt/srcfmt";

  } elsif ($ctan_dir =~ m!/macros/generic/!) {
    $standarddocfmt = $standardsourcefmt = $standardfmt = "generic";
    $guess = "$standarddocfmt for fmt/docfmt/srcfmt";

  } elsif ($ctan_dir =~ m!/(info|help)/!) {
    $standarddest = "texmf-doc";
    $guess = "$standarddest for dest";

  } else {
    $changed = 0;
  }

  print "\t guessed $guess (based on $ctan_dir)\n" if $guess;
}



sub xchdir
{
  my ($dir) = @_;
  chdir ($dir) || die "chdir($dir) failed: $!";
  chomp (my $pwd = `pwd`);
  print "\t CHDIR $dir (now $pwd)\n";
}

sub xmkdir
{
  my (@dirs) = @_;
  &SYSTEM ("mkdir -p @dirs");
}



# some packages (e.g., vntex) are tl-ready (or near enough).
# 
sub MAKEcopy
{
  my $dest = $_[0] || $DEST;
  my $pdir = $packagedir;

  chomp (my $abspackagedir = `cd $pdir && pwd`);
  print "\t COPY from $abspackagedir to $dest\n";

  &xchdir ($pdir);
  &SYSTEM ("mkdir -p $dest");

  # do the copy.
  &SYSTEM ("$CP -r * $dest");

  # for arev et al., remove symlinks.
  &SYSTEM ("find $dest -type l | xargs --no-run-if-empty rm");

  # ditto assorted other for lm (files are in doc subtree already).  
  -r "$dest/MANIFEST.txt"
  && &SYSTEM ("cd $dest && $RM GUST*.txt MANIFEST.txt README.eng");

  # move README for encxvlna and others
  -r "$dest/README" 
  && &SYSTEM ("$MV $dest/README $dest/doc/$whichdocformat/$package/");

  # move CHANGELOG for stellenbosch.
  -r "$dest/CHANGELOG" 
  && &SYSTEM ("$MV $dest/CHANGELOG $dest/doc/$whichdocformat/$package/");

  # move README.eulervm for eulervm.
  -r "$dest/README.eulervm" 
  && &SYSTEM ("$MV $dest/README.eulervm $dest/doc/$whichdocformat/$package/");

  # for tex-gyre, rename context subdir.  (shouldn't be needed next time.)
  if (-d "$dest/fonts/map/pdftex/context") {
    print "$package: rename context map dir.\n";
    &SYSTEM ("$MV $dest/fonts/map/pdftex/context $dest/fonts/map/pdftex/tex-gyre");
  }

  # for eplain, move info file (with warning).
  if (-r "$dest/doc/$package/doc/eplain.info") {
    warn "WARNING: moving eplain.info to /tmp\n";
    warn " -- YOU must put it in texmf/doc/info!\n";
    &SYSTEM ("$MV $dest/doc/$package/doc/eplain.info /tmp");
  }

  # for velthuis, remove bin dir (with warning).
  if ($package eq "velthuis" && -d "$dest/bin") {
    warn "WARNING: removing bin/ dir in $dest\n";
    warn " -- YOU must deal with it!\n";
    &SYSTEM ("rm -rf $dest/bin");
  }

  # preserve the lm sources.
  if ($package eq "lm") {
    my $srcdir = " $dest/source/$whichdocformat/$package/";
    &SYSTEM ("mkdir -p $srcdir");
    &SYSTEM ("$MV $dest/lm*mt1.zip $srcdir/");
  }

  &xchdir ($DEST);
  &killfiles ($specialclean{$package} || $standardclean);
  &killfiles ($moreclean{$package}, "more") if $moreclean{$package};

  my $postaction = $specialpostaction{$package};
  eval ($postaction) if $postaction;
}


# 
# For most packages, this is the first thing called.  It copies
# everything from $packagedir to the doc directory of the package.
# 
sub setup
{
  my ($ctl) = @_;

  print "doing setup($ctl)...\n";
  # precreate the directories we might need
  $DOCDIR = "$DEST/doc/$whichdocformat/$package";
  &SYSTEM ("mkdir -p $DOCDIR");
  &SYSTEM ("mkdir -p $DEST/tex/$whichformat/$package");
  &SYSTEM ("mkdir -p $DEST/source/$whichdocformat/$package");
  
  # remove README symlinks.
  &SYSTEM ("test -h $packagedir/README && $RM $packagedir/README");

  return if $ctl eq "nocopytodoc";
  # copy everything to the doc directory
  # and work in there.
  &SYSTEM ("$CP -r $packagedir/* $DEST/doc/$whichdocformat/$package");
}

sub donormal
{
   my ($ctrl) = @_;

   print "doing donormal($ctrl)...\n";

   # check for tds-ready packages
   if ( -e "$startdir/$packagedir/TDS_READY" ) {
     print "using TDS_READY tree\n";
     &SYSTEM ("$RM $startdir/$packagedir/TDS_READY");
     &SYSTEM ("mkdir -p $DEST");
     &xchdir ($DEST);
     &SYSTEM ("$CP -r $startdir/$packagedir/* .");
   } else {
     #use the normal procedure

     &setup unless $ctrl eq "nosetup";
     &xchdir ("$DEST/doc/$whichdocformat/$package");
     &buildfilelist;

     # run the .ins files (if any) supplied
     $inspatt = $specialins{$package} || $standardins;
     $Foundry = $specialfoundry{$package} || $standardfoundry;
     &runins($inspatt);

     &killfiles ($moreclean{$package}, "more") if $moreclean{$package};

     # rebuild the list of files in the directory
     &buildfilelist;

     if ($Foundry eq "metafont") {
       &dosimplemf;
     } else {
       &domf;
     }

     &dodvi;
     # rebuild again, as we have .dvi files now
     &buildfilelist;
     &dobst;
     &domp;
     &dobib;
     &doxmt;
     &dotex;
     &runfonts;
     &domakeindex;
     &doomega;
     &dosource;
     &dotype1;
     &doscripts;

     # remove empty directories that we never used.
     &SYSTEM ("rmdir $DEST/*/$whichformat/$package 2>/dev/null");

     &killfiles ($specialclean{$package} || $standardclean);
   }

   # do the postaction in any case (we need to adapt some tds zips)
   my $postaction = $specialpostaction{$package};
   eval ($postaction) if $postaction;
}

sub runins
{
  my ($thispatt) = @_;
  print "\t RUNINS $thispatt\n";
  for (grep (/$thispatt/, @filenames)) { 
    # do not infinite loop on docstrip "output directory", e.g., fltpoint.
    &runjob ("yes | sed 5q | $insrunner $_");
  }

  &killfiles ($specialclean{$package} || $standardclean);
}

sub install
{
  my ($destdir,$thispatt) = @_;
  return unless $thispatt;
  
  my @files = grep (/$thispatt/, @filenames);  # ugh, @filenames global
  return unless @files;  # avoid lots of useless output

  print "\t INSTALL $thispatt to $destdir\n";
  &xmkdir ($destdir) unless -d $destdir;

  for my $file (@files) {
    next if $file eq "dtx-style.sty";  # this should never be in runtime
    &SYSTEM ("$MV $file $destdir");
  }
}

# build the documentation files
sub dodvi
{
  # packages which are doc themselves rarely rebuild cleanly,
  # and aren't worth it.
  return if $DEST_TREE eq "texmf-doc";
  $dvipatt = $specialdvi{$package} || $standarddvi;
  unless ( "$dvipatt" eq "$standarddvi" ) {
    warn "$0: Building doc: shouldn't need do to that. Please check.";
    &rundvi ($dvipatt);
  }
}

# move the runtime files
sub dotex
{
  my $texpatt = $specialtex{$package} || $standardtex;
  &install("$DEST/tex/$whichformat/$package", $texpatt);
}

# move the makeindex runtime files
sub domakeindex
{
   $makeindexpatt = $specialmakeindex{$package};
   if ($makeindexpatt eq "") { $makeindexpatt=$standardmakeindex; }
   &install("$DEST/makeindex/$package",$makeindexpatt);
}

# BibTeX style files:
sub dobst
{
   $csfpatt = $specialcsf{$package};
   if ($csfpatt eq "") { $csfpatt=$standardcsf; }
   &install("$DEST/bibtex/csf/$package",$csfpatt);
   $bstpatt = $specialbst{$package};
   if ($bstpatt eq "") { $bstpatt=$standardbst; }
   &install("$DEST/bibtex/bst/$package",$bstpatt);
}

# simple MF files, e.g., if specialfoundry eq "metafont".
sub dosimplemf {
   my $mfpatt = $specialmf{$package} || $standardmf;
   &install ("$DEST/metafont/$package", $mfpatt);
}

# MetaPost files:
sub domp {
   $mppatt = $specialmp{$package} || $standardmp;
   &install("$DEST/metapost/$package", $mppatt);
}

# BibTeX bibliography files:
sub dobib
{
  return if ! $specialbib{$package} && $DEST_TREE eq "texmf-doc";
  $bibpatt = $specialbib{$package} || $standardbib;
  &install("$DEST/bibtex/bib/$package", $bibpatt);
}

# source files:
sub dosource
{
  $sourceformat = $specialsourcefmt{$package} || $standardsourcefmt;
  # default to using specialdocfmt, as we do in setup?
  $sourcepatt = $specialsource{$package} || $standardsource;
  &install("$DEST/source/$sourceformat/$package", $sourcepatt);
}


sub doomega
{
   $ovfpatt = $specialovf{$package};
   if ($ovfpatt eq "") { $ovfpatt=$standardovf; }
   &install("$DEST/fonts/ovf/public/$package",$ovfpatt);
   $ofmpatt = $specialofm{$package};
   if ($ofmpatt eq "") { $ofmpatt=$standardofm; }
   &install("$DEST/fonts/ofm/public/$package",$ofmpatt);
   $ovppatt = $specialovp{$package};
   if ($ovppatt eq "") { $ovppatt=$standardovp; }
   &install("$DEST/fonts/ovp/public/$package",$ovppatt);
   $otppatt = $specialotp{$package};
   if ($otppatt eq "") { $otppatt=$standardotp; }
   &install("$DEST/omega/otp/$package",$otppatt);
   $ocppatt = $specialocp{$package};
   if ($ocppatt eq "") { $ocppatt=$standardocp; }
   &install("$DEST/omega/ocp/$package",$ocppatt);
}

# the dvips and font mapping files:
sub dotype1{
   my $encpatt = $specialenc{$package} || $standardenc;
   &install("$DEST/fonts/enc/dvips/$package", $encpatt);

   my $mappatt = $specialmap{$package} || $standardmap;
   my $mapdest = $specialmapdest{$package} || $standardmapdest;
   &install ("$DEST/$mapdest/$package", $mappatt);

   my $vmappatt = $specialvmap{$package} || $standardvmap;
   &install("$DEST/fonts/map/vtex/$package", $vmappatt);

   my $propatt = $specialpro{$package} || $standardpro;
   &install("$DEST/dvips/$package", $propatt);

   my $pfbpatt = $specialpfb{$package} || $standardpfb;
   &install("$DEST/fonts/type1/public/$package", $pfbpatt);

   my $afmpatt = $specialafm{$package} || $standardafm;
   &install("$DEST/fonts/afm/public/$package", $afmpatt);

   my $pfmpatt = $specialpfm{$package} || $standardpfm;
   &install("$DEST/fonts/type1/public/$package", $pfmpatt);

   my $otfpatt = $specialotf{$package} || $standardotf;
   &install("$DEST/fonts/opentype/public/$package", $otfpatt);

   my $ttfpatt = $specialttf{$package} || $standardttf;
   &install("$DEST/fonts/truetype/public/$package", $ttfpatt);
}

# scripts.  Build/source/tex/texlive/Makefile.in installs symlinks
# in the bin directories where appropriate.  Just for simplicitly, let's
# try keeping DEST as texmf when symlinks get installed; otherwise
# (if it gets called as a subprogram) texmf-dist is ok.
# 
sub doscripts
{
   my $scriptpatt = $specialscripts{$package};
   return unless $scriptpatt;
   &install ("$DEST/scripts/$package", $scriptpatt);
   &SYSTEM ("chmod a+x $DEST/scripts/$package/*");
}

# xmltex files
sub doxmt{
   my $xmtpatt = $specialxmt{$package} || $standardxmt;
   &install ("$DEST/tex/xmltex/$package", $xmtpatt);
}

# build the font files
sub domf {
  $mfpatt = $specialmf{$package} || $standardmf;
  &runmf ($mfpatt);

  my $mfdir = "$DEST/fonts/source/$Foundry/$package";
  #
  # don't use $mfpatt since that's only the tfm-able mf files; just
  # install all the .mf files.
  &install ($mfdir, '\.mf$');
  if (exists $specialmfinstall{$package}) {
    &install ($mfdir, $specialmfinstall{$package});
  }
}

sub rundvi {
   local($thispatt) = @_;
   $TEX = $specialTEX{$package};
   if ($TEX eq "") { 
       if ($whichformat eq 'latex') { $TEX="pdflatex"; }
       else { $TEX=$whichformat; }
   }
   if ($TEX eq "generic") { $TEX="pdflatex"; }
   print "\t MAKEDVI $thispatt using $TEX (@filenames)\n";
   for (grep(/$thispatt/,@filenames)) { 
     ($FileBase,$Filepath,$Filesuffix) = fileparse($_,"\.[A-z]*");
     print "found $FileBase\n";
      if (-r "$FileBase.drv" && $Filesuffix eq ".dtx" ) 
          { $Filesuffix=".drv" ; }
      print "\t DOC: run $TEX on $FileBase$Filesuffix\n";
      open(TMP,">$FileBase.aux");
      close(TMP);
      &runjob("TEXMFLOCAL=. $TEX '\\nonstopmode\\input $FileBase$Filesuffix'");
      &runjob("bibtex $FileBase");
      &runjob("TEXMFLOCAL=. $TEX '\\nonstopmode\\input $FileBase$Filesuffix'");
      if ($Filesuffix eq ".drv" || $Filesuffix eq ".dtx" ) {
        &runjob("$CP $startdir/gind.ist .");
        &runjob("makeindex -s gind.ist $FileBase");
        unlink "gind.ist";
      } else {
        &runjob("makeindex $FileBase");
      }
      &runjob("$TEX '\\nonstopmode\\input $FileBase$Filesuffix'");
   }
   print "\t MAKEDVI done\n";
}

# run a &SYSTEM job, and append stderr output to log file
#
sub runjob
{
  my ($job) = @_;
  
  if ($opt_test) {
    print "WOULDRUNJOB $job\n";
  } else {
    my $Jobid = "_$$";
    &SYSTEM ("$job >$Jobid.log 2>&1");
    local *TMP;
    open (TMP, "$Jobid.log") || die "open($Jobid.log) failed: $!";
    my @output = (<TMP>);
    if ($job =~ /^mktextfm/) {
      print $output[$#output-1];  # successfully generated line
    } else {
      print `cat $Jobid.log`;
    }
    close (TMP);
    unlink ("$Jobid.log");
  }
}

# remove all files matching something in $KILLPATT.
# also remove .ps files for which we have a .pdf.
#
# if MORE is true, remove additional files matching something in
# $moreclean and create a README.TEXLIVE which lists the removed files.
#
# This only deletes files in the current directory.  Should fix.
# 
sub killfiles
{
   my ($killpatt,$more) = @_;

   local *DOT;
   opendir (DOT, ".") || die "opendir(.) failed: $! in " . `pwd`;

   my @delfiles = ();
   for (grep (/$killpatt/, readdir (DOT))) { 
     print "\t Removing $_\n";
     if (unlink ($_)) {
       push (@delfiles, $_);
     } else {
       warn "unlink($_) failed: $!";
     }
   }
   
   for (grep (/\.ps$/, @filenames)) { 
     (my $pdf = $_) =~ s/ps$/pdf/;
     next unless grep (/$pdf/, @filenames);
     print "\t Remove ps $_ (since have $pdf)\n";
     unlink ($_) && push (@delfiles, $_);
   }  

   if ($more && @delfiles) {
     # create/update README.TEXLIVE.
     open RTL, ">README.TEXLIVE" or warn "open(>README.TEXLIVE) failed: $!";
     print RTL <<EOF;
The following files have been removed in the TeX Live installation of
the current package, typically due to duplication, lack of space, or
missing source code.  You can find these files on CTAN.  If questions or
concerns, email tex-live@tug.org.

EOF
     foreach my $f (@delfiles) {
       print RTL "\t$f\n";
     }
     close RTL;
   }
   &buildfilelist();
}

# rebuild list of input files, e.g., after flattening
sub buildfilelist
{
  print "doing buildfilelist()...\n";
  opendir (DIR ,'.') || die "opendir(.) failed: $!";
  @filenames = grep (!/^\.\.?$/, readdir (DIR));
  closedir (DIR);
}

sub runmf
{
  my ($mfpatt) = @_;
  print "\t doing runmf for $package ($mfpatt)\n";
  for my $file (grep (/$mfpatt/, @filenames)) { 
    ($FileBase,$Filepath,$Filesuffix) = fileparse ($file, "\.[A-z]*");
    if (! -e "$FileBase.tfm") {
      print "\t\t Make TFM from $file\n";
      &runjob ("mktextfm --destdir=`pwd` $FileBase.tfm");
      &SYSTEM ("$RM *pk");  # not worth the space
    }
  }
}

sub runfonts {
   $Foundry = $specialfoundry{$package} || $standardfoundry;
   for (grep(/.vf/,@filenames)) { 
      $needdir=1;
      print "\t\t install VF $_\n";
($FileBase,$Filepath,$Filesuffix) = fileparse($_,"\.[A-z]*");
      if ($needdir) { 
         &SYSTEM("mkdir -p $DEST/fonts/vf/$Foundry/$package");
         $needdir=0;
         }
         &SYSTEM("$MV $FileBase.vf $DEST/fonts/vf/$Foundry/$package  ");
    }
   for (grep(/.tfm/,@filenames)) { 
      $needdir=1;
      print "\t\t INSTALL tfm $_\n";
($FileBase,$Filepath,$Filesuffix) = fileparse($_,"\.[A-z]*");
      if ($needdir) { 
         &SYSTEM("mkdir -p $DEST/fonts/tfm/$Foundry/$package");
         $needdir=0;
         }
         &SYSTEM("$MV $FileBase.tfm $DEST/fonts/tfm/$Foundry/$package  ");
    }
}


sub SYSTEM
{
 local ($job) = @_;
 if ($opt_test) {
   print "\t SYSTEM $job\n";
 } else {
   print "\t SYSTEM $job\n" if $opt_debug;
   system($job);
 }
}


sub MAKEflatten
{
  &setup;
  &xchdir ("$DEST/doc/$whichdocformat/$package");

  print "\t SPECIAL flatten $package\n";

  # cm-super et al. need to intervene at this point.
  my $prehook = $flatten_prehook{$package};
  if ($prehook) {
    print "\t FLATTEN_PREHOOK: $prehook\n";
    eval $prehook;
    die "$package failed in $prehook: $@" if $@;
  }

  # mv foo/README to README.foo.  README.txt is for psfragx.
  # Obviously should be generalized.
  &SYSTEM ("for r in `find . -mindepth 2 '(' -name README -o -name README.txt ')'`; do"
           . ' mv $r $r.`basename \`dirname $r\``; done');

  # move all non-directories to top level, but don't accidentally
  # overwrite one with another.
  &SYSTEM ("yes n | find . -mindepth 2 -not -type d  -exec mv -i '\{\}' . \\;");

  # remove newly empty directories.
  &SYSTEM ("find -depth -type d -print | xargs rmdir 2>/dev/null");

  # do the usual.
  &buildfilelist;
  &donormal ("nosetup");
}

sub MAKEunzipandflatten {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &SYSTEM("unzip -q -o -a $package.zip; rm $package.zip");
 &SYSTEM("$MV */*/*/*/* .; rmdir */*/*/*");
 &SYSTEM("$MV */*/*/* .; rmdir */*/*");
 &SYSTEM("$MV */*/*/* .; rmdir */*/*");
 &SYSTEM("$MV */*/* .; rmdir */*");
 &SYSTEM("$MV */*/* .; rmdir */*");
 &SYSTEM("$MV */* .; rmdir *");
 &buildfilelist;
 &donormal;
}

sub MAKEnosymlinks
{
  &setup;
  chdir("$DEST/doc/$whichdocformat/$package");

  print "\t SPECIAL nosymlinks $package\n";
  &SYSTEM("find . -type l | xargs --no-run-if-empty rm");

  &buildfilelist;
  &donormal ("nosetup");
}

# do some stuff for simple packages with hyphenation files, like
# cbcoptic and ibycus-babel.  The arguments are:
# LANGNAME - full language name, like "coptic" (first arg of .dat line)
# LANGABBREV - abbreviated language name, like "cop" (in .dat filename)
# HYPHFILE - hyphenation .tex file name, like "copthyph.tex"
# 
# General procedure is:
# 
# create: tlpkg/tlpsrc/hyphen-language.tlpsrc
#   (must be done by hand)
# create: texmf/tex/generic/config/language.ll.dat
#   (done here, unless it already exists)
# install pattern file from ctan: texmf/tex/generic/hyphen/langhyph.tex
#   (done here)
# add in: tlpkg/tlpsrc/collection-langwhatever.tlpsrc
#   (must be done by hand)
# 
sub GENMAKEhyphenation
{
 my ($langname,$langabbrev,$hyphfile) = @_;
 &setup;
 &buildfilelist;
 &donormal;
 print "\t SPECIAL $package: install $hyphfile\n";
 my $generichyphdir = "$TOPDEST/texmf/tex/generic/hyphen";
 &SYSTEM("mkdir -p $generichyphdir");
 &SYSTEM("$MV $hyphfile $generichyphdir");
 
 my $genericconfigdir = "$TOPDEST/texmf/tex/generic/config";
 my $configfile = "$genericconfigdir/language.$langabbrev.dat";
 if (! -r $configfile) {
   print "\t SPECIAL $package: create $configfile\n";
   &SYSTEM("mkdir -p $genericconfigdir");
   &SYSTEM("echo $langname $hyphfile >$configfile");
 }

 print "YOU-MUST-DO! $package: create hyphen-$langname.tlpsrc\n";
 print "YOU-MUST-DO! $package: add to collection-langwhatever.tpm\n";
}

sub MAKEcbcoptic
{
  &GENMAKEhyphenation ("coptic", "cop", "copthyph.tex");
}

sub MAKEibycusbabel
{
  &GENMAKEhyphenation ("ibycus", "iby", "ibyhyph.tex");
}

# since existing mongolian is written in a different encoding,
# seems best to keep both?
sub MAKEmnhyphn
{
 &GENMAKEhyphenation ("mongolian2a", "mn2a", "mnhyphn.tex");
}

# we don't want a package named nohyph.  Hmm.
#sub MAKEnohyph
#{
# &GENMAKEhyphenation ("norsk", "no", "nohyphbx.tex");
# &GENMAKEhyphenation ("nynorsk", "no", "nnhyph.tex");
# &GENMAKEhyphenation ("bokmal", "no", "nbhyph.tex");
#}

sub MAKEarabi {
  &xchdir ("$packagedir/arabi/texmf");  # author will remove these next time
  #
  print "\t SPECIAL $package - removing microsoft and nonfree\n";
  &SYSTEM('find -name microsoft -o -name nonfree | xargs rm -rf');
  #
  print "\t SPECIAL $package - rearranging for tds\n";
  &SYSTEM ("mkdir -p tex; mv latex tex");
  &SYSTEM ("$RM tex/latex/arabi/updmap.cfg");
  &SYSTEM ("$MV tex/latex/arabi/bblopts.cfg doc/latex/arabi");
  &SYSTEM ("rm -rf dvips");
  #
  print "\t SPECIAL $package - copying to $DEST\n";
  &SYSTEM ("mkdir -p $DEST");
  &SYSTEM ("$CP -r * $DEST/");
}

sub MAKEarabtex {
  &xchdir ($packagedir);
  #
  print "\t SPECIAL $package: removing top-level links\n";
  &SYSTEM('for f in apatch.sty arabtex.tex hebtex.tex hepatch.sty; do test -h $f && rm -v $f; done');
  #
  print "\t SPECIAL $package: removing top-level tgz's\n";
  &SYSTEM('for f in *.tgz; do rm -v $f; done');
  #
  print "\t SPECIAL $package: renaming arabtex.htm\n";
  &SYSTEM('mv doc/html/arabtex.htm arabtex1.htm');
  &SYSTEM('mv doc/txt/arabtex.htm arabtex2.htm');
  #
  print "\t SPECIAL $package: flatten\n";
  &xchdir ("..");
  &MAKEflatten ();
}

sub MAKEarphic {
  &xchdir ($packagedir);
  # tds-ready tarballs with a top-level dir name.  copy all into new/.
  &SYSTEM ("mkdir -p new");
  for my $tar (<*.tar.*>) {
    (my $tarbase = $tar) =~ s/\.tar.*//;
    &SYSTEM ("tar xf $tar "
             . "&& (cd $tarbase && cp -arf * ../new)"
             . "&& rm -rf $tar $tarbase");
  }
  # move everything from new to the top level.
  &SYSTEM ("mv new/* . && rmdir new");
  #
  # move docs to subdir.
  &SYSTEM ("mv arphic-sampler* doc/fonts/arphic");
  #
  # copy to dest.
  &xchdir ("..");
  &MAKEcopy ();
}

sub MAKEaurical {
  &xchdir ($packagedir);
  #
  # basically have a tds hier to unzip, with some cleanups.
  &SYSTEM ("unzip -q aurical_texmf.zip");
  &SYSTEM ("mkdir -p fonts/source/public/aurical/");
  &SYSTEM ("$MV $DEST/README doc/latex/aurical/");
  &SYSTEM ("$MV aurical_source.zip fonts/source/public/aurical/");
  &SYSTEM ("$RM aurical.pdf aurical_texmf.zip");
  #
  &xchdir ("..");
  &MAKEcopy ();
}

sub MAKEeskdx {
 &setup;
 &xchdir ("$DEST/doc/$whichdocformat/$package");
 print "\t SPECIAL $package: flatten unpacked/ dir (only)\n";
 &SYSTEM ("$MV unpacked/Makefile Makefile.unpacked");
 &SYSTEM ("$MV unpacked/* .");
 &SYSTEM ("rmdir unpacked");
 &buildfilelist;
 &donormal;
}

sub MAKEmathdesign {
  &setup ();
  &xchdir ($DOCDIR);
  #
  # basically have several tds hiers to unzip, with some cleanups.
  print "\t SPECIAL $package: unzip etc.\n";
  for my $zip (<*.zip>) {
    &SYSTEM ("cd $DEST && unzip -q -o $DOCDIR/$zip; $RM $DOCDIR/zip");
  }
  &SYSTEM ("rm -rf commercialfonts");
  &SYSTEM ("mv $DEST/dvips/config $DEST/dvips/mathdesign");
}

sub MAKEmetauml {
 &setup;
 &xchdir ("$DEST/doc/$whichdocformat/$package");
 &SYSTEM ("$MV doc/* examples/* inputs/* .");
 &SYSTEM ("rmdir doc examples inputs");
 &buildfilelist;
 &donormal;
}

sub MAKEmflogo{ 
 &setup;
  chdir("$DEST");
  &runjob("tar xvf $DEST/doc/latex/$package/logofont.tar");
  chdir("$DEST/doc/latex/$package");
  &donormal;
 }

sub MAKEfp {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &runjob("mkdir -p $DEST/tex/plain/fp; $CP fp.tex $DEST/tex/plain/fp");
 &donormal;
}

sub MAKEgermbib {
  &xchdir ($packagedir);
  #
  print "\t SPECIAL $package remove symlinks\n";
  &SYSTEM ("find . -type l | xargs --no-run-if-empty rm");
  #
  # we can't conflict with standard apalike.sty.
  print "\t SPECIAL $package rename second apalike.sty\n";
  &SYSTEM ("$MV styles/apalike.sty styles/apalike.germbib_sty");
  #
  # spurious ^M's.
  &SYSTEM ("perl -pie 'tr/\r//' document/btxdoc.tex");
  #
  &xchdir ("..");  
  &MAKEflatten ();
}

sub MAKExkeyval {
  # needs files in both latex and generic.
  &MAKEflatten ();
  print "\t SPECIAL $package moving .tex\n";
  my $generic = "$DEST/tex/generic/$package/";
  &SYSTEM ("mkdir -p $generic; mv *.tex $generic");
}

sub MAKExymtex {
 &setup;
 chdir("$DEST/doc/latex/$package");
 &SYSTEM("$MV doc200/* .");
 &SYSTEM("rmdir doc");
 &buildfilelist;
 &donormal;
}

sub MAKEnewsletr {
  &setup;
  chdir("$DEST/doc/$whichdocformat/$package");
  &SYSTEM ("$MV newsletr.tex $DEST/tex/$whichformat/$package");
  &SYSTEM ("$RM *.dvi");
}

sub MAKEpbdiagram {
 &setup;
 chdir("$DEST/doc/latex/$package");
 &SYSTEM("rm -rf mf tfm");
 &buildfilelist;
 &donormal;
}

# copy seminar files.
sub MAKEseminar {
 &SYSTEM("mkdir -p $DEST/tex/latex/$package");
 &SYSTEM("$CP $packagedir/inputs/* $DEST/tex/latex/$package");
 #
 &SYSTEM("mkdir -p $DEST/source/latex/$package");
 &SYSTEM("$CP $packagedir/src/* $DEST/doc/latex/$package");
 #
 &SYSTEM("mkdir -p $DEST/doc/latex/$package");
 &SYSTEM("$CP $packagedir/*read* $packagedir/doc/* $DEST/doc/latex/$package");
}

sub MAKExypic {
# this simply copies source files as per INSTALL instructions
   chdir($packagedir) || die ("ERROR: cannot open directory");
  &runjob("mkdir -p $DEST/fonts/source/$Foundry/xypic");
  &runjob("mkdir -p $DEST/fonts/type1/$Foundry/xypic");
  &runjob("mkdir -p $DEST/fonts/tfm/$Foundry/xypic");
  &runjob("mkdir -p $DEST/fonts/pk/cx/$Foundry/xypic");
  &runjob("mkdir -p $DEST/tex/generic/xypic");
  &runjob("mkdir -p $DEST/dvips/xypic");
  &runjob("mkdir -p $DEST/doc/generic/xypic");
  &runjob("mkdir -p $DEST/source/generic/xypic");
  &runjob("$CP texinputs/* $DEST/tex/generic/xypic");
  &runjob("$CP texfonts/* $DEST/fonts/tfm/$Foundry/xypic");
  &runjob("$CP mfinputs/* $DEST/fonts/source/$Foundry/xypic");
  &runjob("$CP src/* $DEST/doc/generic/xypic");
  &runjob("$CP type1/* $DEST/fonts/type1/$Foundry/xypic");
  &runjob("$CP ps/* $DEST/dvips/xypic");
  &runjob("$CP doc/*.* $DEST/doc/generic/xypic");
  &runjob("$CP [A-Z]* $DEST/doc/generic/xypic");
  open (TMP,">$DEST/texmf-dist/dvips/xypic/config.xyp");
  print TMP "p +xypic.map";
  close(TMP);
# do the PK files
  chdir("pkfonts");
  &buildfilelist;  
  for (@filenames) { 
    if (-d $_) {
        chdir $_;
        s/cx([0-9]*)//;
        $dpi=$1;
 opendir(DIR,'.');
 @ffontnames =grep(!/^\.\.?$/,readdir(DIR));
 closedir(DIR);
        for (@ffontnames) { 
($FileBase,$Filepath,$Filesuffix) = fileparse($_,"\.[A-z0-9]*");
        &SYSTEM("mkdir -p $DEST/fonts/pk/cx/$Foundry/xypic/dpi$dpi");
        &SYSTEM("$MV $_ $DEST/fonts/pk/cx/$Foundry/xypic/dpi$dpi/$FileBase.pk");
               }
       chdir '..';
           }
    }
}


sub MAKEborceux {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package/user-guides");
 &SYSTEM("$MV -f * $DEST/doc/$whichdocformat/$package");
 chdir("$DEST/doc/$whichdocformat/$package/diagram");
 &SYSTEM("$MV -f * $DEST/tex/$whichformat/$package");
}

sub MAKEconcmath {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &SYSTEM("$MV fonts/*/* .");
   &buildfilelist;
   &domf;
   &dodvi;
# rebuild again, as we have .dvi files now
   &buildfilelist;
   &domakeindex;
   &dotex;
   &dosource;
}

sub MAKEplqx {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &SYSTEM("$MV tex/* .");
 &SYSTEM("$MV doc/* .");
 &SYSTEM("rmdir doc tex");
 &buildfilelist;
 &donormal;
}

sub MAKEaugie {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &SYSTEM("$MV dvips/* .");
 &SYSTEM("$MV tfm/* .");
 &SYSTEM("$MV afm/* .");
 &SYSTEM("$MV doc/* .");
 &SYSTEM("$MV vf/* .");
 &SYSTEM("$MV tex/* .");
 &SYSTEM("$MV type1/* .");
 &SYSTEM("rmdir type1 tex vf afm dvips doc tfm");
 &buildfilelist;
 &donormal;
}

sub MAKEae {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &SYSTEM("$MV tfm/* .");
 &SYSTEM("$MV vf/* .");
 &SYSTEM("$MV src/* .");
 &SYSTEM("$MV tex/* .");
 &SYSTEM("rmdir tex vf src tfm");
 &buildfilelist;
 &dosource;
 &dotex;
   &domakeindex;
 &runfonts;
}

sub MAKEdevanagr {
 &xchdir ($packagedir);
 #
 print "\t SPECIAL $package: renaming README files\n";
 &SYSTEM('for f in *; do test -r $f/README && mv $f/README README.$f; done');
 #
 print "\t SPECIAL $package: moving .c and .exe to /tmp\n";
 &SYSTEM('mv bin/devnag.c bin/devnag.exe /tmp');
 #
 print "\t SPECIAL $package: flatten\n";
 &xchdir ("..");
 &MAKEflatten;
 print "YOU-MUST-DO! update /tmp/devnag.c and devnag.exe into Build\n";
}

# We don't want to flatten the templates, only the source.
# 
sub MAKEdisser
{
  &setup;
  &xchdir ("$DEST/doc/$whichdocformat/$package");
  print "\t SPECIAL $package\n";
  &SYSTEM ("$MV -f src/* .");
  &buildfilelist;
  &donormal ("nosetup");
}

sub MAKEeasy {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &SYSTEM("rm doc/*.ps");
 &SYSTEM("$MV doc/* $DEST/doc/$whichdocformat/$package");
   &buildfilelist;
   &dodvi;
# rebuild again, as we have .dvi files now
   &buildfilelist;
   &dotex;
   &domakeindex;
   &dosource;
}

sub MAKEebong {
 &xchdir ($packagedir);
 #
 print "\t SPECIAL $package: moving .py to /tmp\n";
 &SYSTEM('mv -v *.py /tmp');
 #
 print "\t SPECIAL $package: flatten\n";
 &xchdir ("..");
 &MAKEflatten;
 print "YOU-MUST-DO! update /tmp/ebong.py into Build\n";
}

sub MAKEfootnpag {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &SYSTEM("$MV src/* .");
   &buildfilelist;
   &dodvi;
# rebuild again, as we have .dvi files now
   &buildfilelist;
   &dotex;
   &domakeindex;
   &dosource;
}


sub MAKEeplain {
  print "\t SPECIAL $package\n";
  &setup;
  &xchdir ($DEST);
  rename ("tex/eplain/eplain", "tex/eplain/base");
  &SYSTEM ("$MV $DOCDIR/eplain.tex tex/eplain/base");
  &SYSTEM ("$MV $DOCDIR/btxmac.tex tex/eplain/base");
  &SYSTEM ("$MV $DOCDIR/arrow.tex tex/eplain/base");

  &SYSTEM ("$MV $DOCDIR/doc doc/eplain/base");
  &SYSTEM ("$MV $DOCDIR/[A-L]* $DOCDIR/[M-Z]* doc/eplain/base/");
  unlink ("doc/eplain/base/texinfo.tex");
  
  rename ("source/eplain/eplain", "source/eplain/base");
  &SYSTEM ("$MV $DOCDIR/* source/eplain/base");

}

sub MAKEfeynmf
{
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &SYSTEM("gunzip manual.ps");
 &buildfilelist;
 &runins('feynmf.ins');
 &buildfilelist;
 &dosimplemf;
 &dodvi;
 &buildfilelist;
 &domp;
 &dotex;
 &domakeindex;
 &dosource;
 killfiles($standardclean);
}

sub MAKEchangebar {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &buildfilelist;
 &donormal;
}

sub MAKEot2cyr {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &buildfilelist;
 &dodvi;
 &buildfilelist;
 &dotex;
 &domakeindex;
 &dosource;
 &SYSTEM("mkdir -p $DEST/fonts/afm/monotype/timescyr");
 &SYSTEM("$MV mnt*.afm $DEST/fonts/afm/monotype/timescyr");
 &SYSTEM("mkdir -p $DEST/fonts/tfm/monotype/timescyr");
 &SYSTEM("$MV mnt*.tfm $DEST/fonts/tfm/monotype/timescyr");
 &SYSTEM("mkdir -p $DEST/fonts/vf/monotype/timescyr");
 &SYSTEM("$MV mnt*.vf $DEST/fonts/vf/monotype/timescyr");
 &SYSTEM("mkdir -p $DEST/fonts/tfm/bh/luccyr");
 &SYSTEM("$MV hl*.tfm ls*.tfm $DEST/fonts/tfm/bh/luccyr");
 &SYSTEM("mkdir -p $DEST/fonts/vf/bh/luccyr");
 &SYSTEM("$MV hl*.vf $DEST/fonts/vf/bh/luccyr");
 killfiles($standardclean);
}
sub MAKEsiam {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &buildfilelist;
 &dodvi;
 &buildfilelist;
 &dobst;
 &dotex;
   &domakeindex;
 &dosource;
 &SYSTEM("mkdir -p $DEST/doc/plain/siam");
 &SYSTEM("mkdir -p $DEST/doc/amstex/siam");
 &SYSTEM("mkdir -p $DEST/tex/plain/siam");
 &SYSTEM("mkdir -p $DEST/tex/plain/amstex");
 &SYSTEM("$MV plain/*doc* $DEST/doc/plain/siam");
 &SYSTEM("$MV plain/* $DEST/tex/plain/siam");
 &SYSTEM("$MV amstex/*doc* $DEST/doc/amstex/siam");
 &SYSTEM("$MV amstex/* $DEST/tex/amstex/siam");
 killfiles($standardclean);
}

sub MAKEmisc {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &buildfilelist;
 &dotex;
   &domakeindex;
 killfiles($standardclean);
}

sub MAKEtamethebeast {
  my $destdir = "$DEST/doc/english/$package";
  &SYSTEM("mkdir -p $destdir");
  &SYSTEM("$CP -r $packagedir/* $destdir");
}

sub MAKEtexdraw {
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &buildfilelist;
 &dotex;
   &domakeindex;
 &SYSTEM("mkdir -p $DEST/doc/generic/texdraw");
 &SYSTEM("$MV manual/* $DEST/doc/generic/texdraw");
 killfiles($standardclean);
}

sub MAKEexpressg {
 &setup;
chdir("$DEST/doc/$whichdocformat/$package");
&buildfilelist;
   $inspatt = $specialins{$package};
   &buildfilelist;
   if ($inspatt eq "") { 
        $inspatt=$standardins; 
        }
&runins($inspatt);
 &SYSTEM("mpost expeg.mp");
# rebuild the list of files in the directory
 &buildfilelist;
 &dodvi;
# rebuild again, as we have .dvi files now
 &buildfilelist;
 &runfonts;
&dobst;
 &dobib;
&dotex;
   &domakeindex;
 &dosource;
 &dotype1;
#
# this is a bit weird, but its an easy way to remove
# empty directories that we never used.
#
   &SYSTEM("rmdir $DEST/tex/$whichformat/$package 2> /dev/null");
   &SYSTEM("rmdir $DEST/doc/$whichdocformat/$package 2> /dev/null");
   &SYSTEM("rmdir $DEST/source/$whichformat/$package 2> /dev/null");
   killfiles($standardclean);
}

sub MAKEtipa {
# this simply copies source files
   chdir($packagedir) || die ("ERROR: cannot open directory");
  &runjob("mkdir -p $DEST/fonts/source/$Foundry/tipa");
  &runjob("mkdir -p $DEST/fonts/type1/$Foundry/tipa");
  &runjob("mkdir -p $DEST/fonts/tfm/$Foundry/tipa");
  &runjob("mkdir -p $DEST/fonts/map/dvips/tipa");
  &runjob("mkdir -p $DEST/tex/latex/tipa");
  &runjob("mkdir -p $DEST/doc/fonts/tipa");
  &runjob("mkdir -p $DEST/source/latex/tipa");
  &runjob("$CP dvips/* $DEST/fonts/map/dvips/tipa");
  &runjob("$CP sty/* $DEST/tex/latex/tipa");
  &runjob("$CP tfm/* $DEST/fonts/tfm/$Foundry/tipa");
  &runjob("$CP type1/* $DEST/fonts/type1/$Foundry/tipa");
  &runjob("$CP mf/* $DEST/fonts/source/$Foundry/tipa");
  &runjob("$CP doc/* $DEST/doc/fonts/tipa");
}

sub MAKEpslatex {
# this simply copies source files
  chdir($packagedir) || die ("ERROR: cannot open directory");
  $Foundry = $specialfoundry{$package} || $standardfoundry;
  &runjob("mkdir -p $DEST/fonts/tfm/$Foundry/pslatex");
  &runjob("mkdir -p $DEST/fonts/vf/$Foundry/pslatex");
  &runjob("mkdir -p $DEST/tex/latex/pslatex");
  &runjob("mkdir -p $DEST/dvips/pslatex");
  &runjob("mkdir -p $DEST/doc/latex/pslatex");
  &runjob("$CP latex/* $DEST/tex/latex/pslatex");
  &runjob("$CP tfm/* $DEST/fonts/tfm/$Foundry/pslatex");
  &runjob("$CP vf/* $DEST/fonts/vf/$Foundry/pslatex");
  &runjob("$CP dvips/* $DEST/fonts/map/dvips/pslatex");
  &runjob("$CP -r fontinst $DEST/doc/latex/pslatex");
  &runjob("$CP -r shell $DEST/doc/latex/pslatex");
}

sub MAKEeco {
# this simply copies source files
   chdir($packagedir) || die ("ERROR: cannot open directory");
  &runjob("mkdir -p $DEST/fonts/tfm/$Foundry/eco");
  &runjob("mkdir -p $DEST/fonts/vf/$Foundry/eco");
  &runjob("mkdir -p $DEST/tex/latex/eco");
  &runjob("mkdir -p $DEST/dvips/eco");
  &runjob("mkdir -p $DEST/doc/latex/eco");
  &runjob("$CP src/*sty $DEST/tex/latex/eco");
  &runjob("$CP fd/* $DEST/tex/latex/eco");
  &runjob("$CP tfm/* $DEST/fonts/tfm/$Foundry/eco");
  &runjob("$CP vf/* $DEST/fonts/vf/$Foundry/eco");
  &runjob("$CP -r src/*tex src/*x src/*sh $DEST/doc/latex/eco");
  &runjob("$CP -r [A-Z]* $DEST/doc/latex/eco");
 }

sub MAKEelhyphen {
 &setup;
 &buildfilelist;
 &donormal;

 print "\t SPECIAL $package: lowercase names\n";
 &SYSTEM('for f in GR*hyph*.tex; do mv $f `echo $f | tr A-Z a-z`; done');
 
 print "\t SPECIAL $package: install gr*hyph.tex files\n";
 my $generichyphdir = "$TOPDEST/texmf/tex/generic/hyphen";
 &SYSTEM("mkdir -p $generichyphdir");
 &SYSTEM("$MV gr*hyph*.tex $generichyphdir");

 print "YOU-MUST-DO! $package: update texmf/tex/generic/config/language.gr.dat\n";
 print "YOU-MUST-DO! $package: update texmf/tpm/hyphen-greek.tpm\n";
 print "YOU-MUST-DO! $package: add to texmf/tpm/collection-langgreek.tpm\n";
}

sub MAKECatalogue {
# this simply copies source files
   $DEST="$TDS/catalogue/texmf-doc";
   chdir($packagedir) || die ("ERROR: cannot open directory");
  &runjob("mkdir -p $DEST/doc/english/catalogue");
  &runjob("$CP -r * $DEST/doc/english/catalogue");
  chdir("$DEST/doc/html/catalogue/entries") || die ("ERROR cannot chdir $DEST/doc/english/catalogue/entries");
  &buildfilelist;
   foreach $File (grep(/.html$/,@filenames)) { 
    print "process $File\n";
    open FOO,">$File.new";
    open BAR,"$File";
    while (<BAR>) {
      s|\.\./\.\./\.\.|http://theory.uwinnipeg.ca/scripts/CTAN|g;
      print FOO ;
   }
    close FOO;
    close BAR;
    &SYSTEM("$MV $File.new $File");
  }
 }

sub MAKEFAQen
{
  &donormal ();
  &SYSTEM ("tar xzf FAQ-html.tar.gz && rm FAQ-html.tar.gz");
}

# all the lshort translations are pretty similar.
sub MAKElshort
{
  print "MAKElshort $package\n";
  (my $lang = $package) =~ s,.*-,,;  # lshort-english -> english
  my $destdir = "$DEST/doc/$lang/$package";
  &SYSTEM ("mkdir -p $destdir");
  &SYSTEM ("$CP -r $packagedir/* $destdir");
  # keep only pdf's to save space.
  &SYSTEM ("cd $destdir && $RM lshort*.ps *lshort*.ps.*z* lshort*.dvi lshort-*-book.zip");
  # remove symlinks such as README.
  &SYSTEM ("cd $destdir && find -type l | xargs --no-run-if-empty rm");
}

sub MAKEltt {
# this simply copies source files
   chdir($packagedir) || die ("ERROR: cannot open directory");
  &runjob("mkdir -p $DEST/doc/ltt");
  &runjob("$CP * $DEST/doc/ltt");
 }

sub MAKEpstricks
{
  # move the directories around.
  &xchdir ($packagedir);
  &xmkdir ("$DEST/doc/generic");
  #
  my $docdir = "$DEST/doc/generic/pstricks";
  &SYSTEM ("$MV doc $docdir");
  #
  # move multiple Changes files out of runtime.
  &runjob("$MV generic/Changes $docdir/Changes.generic");
  &runjob("$MV latex/Changes $docdir/Changes.latex");
  &runjob("$MV dvips/Changes $docdir/Changes.dvips");
  #
  &xmkdir ("$DEST/dvips");
  &SYSTEM ("$MV dvips $DEST/dvips/pstricks");
  #
  &xmkdir ("$DEST/tex/generic");
  &SYSTEM ("$MV generic $DEST/tex/generic/pstricks");
  #
  &xmkdir ("$DEST/tex/latex");
  &SYSTEM ("$MV latex $DEST/tex/generic/pstricks");
}

sub MAKEwilson
{
 &setup;

 my $docdir = "$DEST/doc/$whichdocformat/$package";
 &xchdir ($docdir);

 my $mapdir = "$DEST/fonts/map/dvips/$package";
 -d $mapdir || &SYSTEM ("mkdir -p $mapdir");
 &SYSTEM ("$MV *.map $mapdir");  # archaicprw.map

 opendir (DIR, '.') || die "opendir(.) failed: $!";
 @dirnames = grep (!/^\.\.?$/, readdir (DIR));
 closedir (DIR);

 for my $d (@dirnames) {
   if ($d =~ /\.zip$/) {
     unlink ("$docdir/$d");
     next;
   }
   
   # phaistos and linearA are nothing to do with Wilson's archaic, but
   # are separate packages created by AS.
   if ($d =~ /^(phaistos|linearA)$/) {
     &SYSTEM ("rm -rf $d $docdir/$d");
     next;
   }
   
   my $target = "$docdir/$d";
   next if ! -d $target;  # samples/readme files
   print "\t PROCESS Wilson subdir $d\n";
   &xchdir ($target);

   if ($d) {
     for my $f (glob ("try*"), glob ("*.pdf"), "README") {
       my $dest = "$docdir/";
       $dest .= "$d-" if $f !~ /$d/;
       $dest .= $f;
       &runjob("$MV $f $dest");
     }
   }

   &buildfilelist;
   # run the .ins files (if any) supplied
   $inspatt = $specialins{$package};
   &buildfilelist;
   &runins($inspatt || $standardins);
   &dodvi;
   &domf;
   &dodvi;
# rebuild again, as we have .dvi files now
   &buildfilelist;
   &runfonts;
   &dobst;
   &dobib;
   &dotex;
   &domakeindex;
   &dosource;
   &dotype1;
   killfiles($standardclean);
 }
 killfiles($standardclean);
}

sub MAKEt2 {
# this simply copies source files
 chdir($packagedir) || die ("ERROR: cannot open directory");
  &runjob("mkdir -p $DEST/dvips/t2");
  &runjob("mkdir -p $DEST/tex/fontinst/cyrfinst");
  &runjob("mkdir -p $DEST/tex/plain/cyrplain");
  &runjob("mkdir -p $DEST/tex/latex/t2");
  &runjob("mkdir -p $DEST/doc/generic/t2");
  &runjob("$CP -r cyrfinst/* $DEST/tex/fontinst/cyrfinst");
  &runjob("$CP -r cyrplain/* $DEST/tex/plain/cyrplain");
  &runjob("$CP enc-maps/encfiles/* $DEST/fonts/enc/t2");
  &runjob("$CP enc-maps/*.* enc-maps/[A-Z]* $DEST/doc/generic/t2");
  &runjob("$CP -r etc examples $DEST/doc/generic/t2");
  chdir("$DEST/doc/generic/t2/etc");
  &runjob("latex mathtext.ins");
  &runjob("rm *log; mv *sty $DEST/tex/latex/t2");
 }

# docs in two languages.  The English one is in a separate package,
# mathmode.  Just remove it from the copy when building the German one.
# 
sub MAKEvossde {
  my $docdir = "$DEST/doc/german/$package";
  &SYSTEM("mkdir -p $docdir");
  &SYSTEM("$CP -r $packagedir/* $docdir");
  &SYSTEM("rm -r $docdir/mathmode");
}


# wadalab provides nearly TDS-ready .tar.gz with additional stuff
#
sub MAKEwadalab
{
  print "MAKEwadalab $package - munge tds-ready tarballs\n";
  &setup;
  &xchdir ("$DEST/doc/$whichdocformat/$package");

  # each XX.tar.gz contains a tds-ready tree under XX/texmf: use it
  opendir (HERE, ".") || die "opendir(.) failed: $!";
  my @tarfiles = grep /\.tar\.gz$/, readdir HERE;
  closedir (HERE);
  #  
  my $destfonts = "$DEST/fonts";
  &SYSTEM ("mkdir -p $destfonts");
  foreach my $tarfile (@tarfiles) {
    &SYSTEM ("tar xzf $tarfile && rm $tarfile");
    $tarfile =~ s/\.tar\.gz$//;
    &SYSTEM ("cp -r $tarfile/texmf/* $DEST");
    &SYSTEM ("rm -r $tarfile/texmf && rmdir $tarfile");
  }
  #
  # except the mincho-1-8-* tarball misses the doc/fonts level.
  &SYSTEM ("$MV $DEST/doc/wadalab/* $DEST/doc/fonts/wadalab/");
  #
  # wadalab has a dir of xdelta from the original fonts.  Remove it.
  -d "xdelta" && &SYSTEM ("rm -rf xdelta");
  #
  # rm unused directories.
  &SYSTEM ("rmdir $DEST/*/$whichformat/$package 2>/dev/null");
}


sub MAKEwordcount {
 &xchdir ($packagedir);
 #
 print "\t SPECIAL $package: moving wordcount.sh to /tmp\n";
 &SYSTEM('mv wordcount.sh /tmp/');
 #
 &xchdir ("..");
 &donormal ();
 #
 print "YOU-MUST-DO! update /tmp/wordcount.sh to source/texk/texlive\n";
}

sub MAKEukrhyph {
# this simply copies source files
  chdir($packagedir) || die ("ERROR: cannot open directory");
  &runjob("mkdir -p $DEST/tex/generic/ukrhyph");
  &runjob("mkdir -p $DEST/doc/generic/ukrhyph");
  &runjob("$CP README $DEST/doc/generic/ukrhyph");
  &runjob("$CP *.* $DEST/tex/generic/ukrhyph");
  &runjob("$MV $DEST/tex/generic/ukrhyph/*.pdf $DEST/doc/generic/ukrhyph");
  &runjob("rm $DEST/tex/generic/ukrhyph/*.ps");
 }

sub MAKElfb {
  # remove pregenerated pk files.
  &MAKEflatten ();
  print "\t SPECIAL removing lfb PK files\n";
  &SYSTEM("rm *pk");
}

sub MAKEliterat {
# this simply copies source files
   chdir($packagedir) || die ("ERROR: cannot open directory");
  &runjob("mkdir -p $DEST/fonts/tfm/paragrap/literat");
  &runjob("mkdir -p $DEST/fonts/vf/paragrap/literat");
  &runjob("mkdir -p $DEST/fonts/type1/paragrap/literat");
  &runjob("mkdir -p $DEST/fonts/afm/paragrap/literat");
  &runjob("mkdir -p $DEST/tex/latex/literat");
  &runjob("mkdir -p $DEST/dvips/literat");
  &runjob("mkdir -p $DEST/doc/fonts/literat");

  &runjob("$CP dvips/* $DEST/dvips/literat");
  &runjob("$CP tex/*tex $DEST/doc/fonts/literat");
  &runjob("$CP psfonts/*pfb $DEST/fonts/type1/paragrap/literat");
  &runjob("$CP psfonts/*inf $DEST/fonts/type1/paragrap/literat");
  &runjob("$CP psfonts/*afm $DEST/fonts/afm/paragrap/literat");
  &runjob("$CP tex/*sty tex/*fd $DEST/tex/latex/literat");
  &runjob("$CP tfm/* $DEST/fonts/tfm/paragrap/literat");
  &runjob("$CP tfm-raw/* $DEST/fonts/tfm/paragrap/literat");
  &runjob("$CP vf/* $DEST/fonts/vf/paragrap/literat");
  &runjob("$CP [A-Z]* insta* license $DEST/doc/fonts/literat");
 }


sub MAKExmltex {
# this simply copies source files
   chdir($packagedir) || die ("ERROR: cannot open directory");
  &runjob("mkdir -p $DEST/tex/xmltex/config");
  &runjob("mkdir -p $DEST/tex/xmltex/base");
  &runjob("mkdir -p $DEST/doc/xmltex/base");

  &runjob("$CP *.ini $DEST/tex/xmltex/config");
  &runjob("$CP xmltex.tex *xmt xmltex.cfg $DEST/tex/xmltex/base");
  &runjob("$CP manual* *xml test* *txt  $DEST/doc/xmltex/base");
 }

sub MAKEbase {
  &SYSTEM("mkdir -p $DEST/tex/latex/base");
  &SYSTEM("mkdir -p $DEST/doc/latex/base");
  &SYSTEM("mkdir -p $DEST/doc/latex/base");
  if (-f "$packagedir/00Contents" ) { unlink "$packagedir/00Contents" ; }
  &SYSTEM("$CP -r $packagedir/* $DEST/doc/latex/base");
  chdir($packagedir) || die ("ERROR: cannot open directory");
  $package="base";
  $DEST="$TDS/ltxbase/texmf-dist";
  print "!$whichformat $packagedir ($package) -> $DEST\n";
  &donormal;
 }

sub MAKEfancyvrb {
 &setup;
 chdir("$DEST/doc/latex/$package");
 print "\t SPECIAL $package: move contrib\n";
 &SYSTEM("$MV contrib/README README.contrib");
 &SYSTEM("$MV contrib/* .; rmdir contrib");
 &buildfilelist;
 &donormal("nosetup");
}

sub MAKEfeatpost {
 &setup;
 chdir("$DEST/doc/metapost/$package") 
   || die "chdir($DEST/doc/metapost/$package) failed: $!";
 print "\t SPECIAL $package, leaving most in doc\n";
 @filenames = glob("macro/*.mp");
 &install("$DEST/metapost/featpost", ".mp");
 &SYSTEM("rm -rf system");  # seeing his texmf.cnf will only confuse people
}

sub MAKEucs {
 &setup;
 chdir("$DEST/doc/latex/$package");
 &SYSTEM("$MV data $DEST/tex/latex/ucs");
 &SYSTEM("$MV *def *sty $DEST/tex/latex/ucs");
 &SYSTEM("$MV contrib/* $DEST/tex/latex/ucs");
}

sub MAKEtexsis {
 &setup;
 chdir("$DEST/doc/texsis/$package");
 &SYSTEM("make TXSsite.tex");
 &buildfilelist;
 &donormal;
 &SYSTEM("rm *.ps");
}


sub MAKEIEEEtran {
 print "\t SPECIAL renaming README files, then flatten\n";
 chdir ($packagedir) || die "chdir($packagedir) failed: $!";
 &SYSTEM('for f in *; do test -r $f/README && mv $f/README README.$f; done');
 chdir ("..");
 &MAKEflatten;
 # let's not worry about the fact that the tex run on testflow fails (it
 # wants a paper size); we still get the distributed pdf, which is good enough.
}

sub MAKEbardiag {
 &setup;
 chdir("$DEST/doc/latex/$package");
 &SYSTEM("$MV doc/* .");
 &buildfilelist;
 &donormal;
}


sub MAKEmathpazo {
 &setup;
 chdir("$DEST/doc/latex/$package");
 &SYSTEM("$MV latex/* type1/* afm/* vf/* tfm/* dvips/* .; rmdir latex type1 afm vf tfm dvips");
 &buildfilelist;
 &donormal;
}

sub MAKEhaprosper {
 &setup ("nocopytodoc"); # create dirs but that's all
 chdir("$packagedir");
 &SYSTEM("mkdir -p $DEST");
 print "\t SPECIAL copying HA-prosper\n";
 &SYSTEM("$CP -r README Doc/* $DEST/doc/latex/HA-prosper");
 &SYSTEM("$CP -r Run/* $DEST/tex/latex/HA-prosper");
 &SYSTEM("$CP -r Source/* $DEST/source/latex/HA-prosper");
}

sub MAKEpclnfss {
 chdir("$packagedir");
 &SYSTEM("mkdir -p $DEST/source/fonts/pclnfss");
 &SYSTEM("mkdir -p $DEST/doc/fonts/pclnfss");
 &SYSTEM("$CP -r [A-Z]* $DEST/doc/fonts/pclnfss");
 &SYSTEM("$CP -r fonts $DEST");
 &SYSTEM("$CP -r tex $DEST");
 &SYSTEM("$CP -r src/* tests $DEST/source/fonts/pclnfss");

}

sub MAKEpdf_forms_tutorial
{
  # called for both the en and de versions.  both are the same catalogue
  # entry, which is rather excruciating for us.
  &xchdir ($packagedir);
  
  my $lang;
  my $ll = substr ($package, -2);  # en or de
  if ($ll eq "en") {
    $lang = "english";
  } elsif ($ll eq "de") {
    $lang = "german";
  } else {
   die "unexpected language code for $package: $ll";
  }
  
  my $dest_lang = "$DEST/doc/$lang";
  my $dest_pkg = "$dest_lang/pdf-forms-tutorial-$ll";
  &SYSTEM ("mkdir -p $dest_lang");
  &SYSTEM ("$CP -r $ll $dest_pkg");
  &SYSTEM ("$CP README fdl.txt $dest_pkg");
}

sub MAKEbeamer {
 &xchdir ($packagedir);
 my $destdoc = "$DEST/doc/latex/beamer";
 &SYSTEM ("mkdir -p $destdoc");
 &SYSTEM ("$CP -r * $destdoc");
 &xchdir ($destdoc);
 
 my $desttex = "$DEST/tex/latex/beamer";
 &SYSTEM("mkdir -p $desttex");
 &SYSTEM("$MV base/* themes emulation extensions/multimedia $desttex");
}


# this doesn't work.
sub MAKEbeebe {
 &setup;
 print "\t SPECIAL moving beebe .bib and .bst\n";
 chdir ("$DEST/doc/latex/$package") || die;
 &SYSTEM("mkdir -p $DEST/bibtex/bib/beebe $DEST/bibtex/bst/beebe");
 &SYSTEM("$MV tex*.bib tug*.bib $DEST/bibtex/bib/beebe");
#xx ugh, they aren't there &SYSTEM("$MV *.bst $DEST/bibtex/bst/beebe");
 &SYSTEM("rm *");
 
}
# pstricks packages usually support both plain and latex.
# 
sub MAKEpst
{
   print "\t SPECIAL pst $package starts\n";
   $standardtex = qq{^$package(Obj)?\.(tex|sty)};  # for pst-laboObj.tex
   $whichformat='generic';
   $whichdocformat='generic';
   $specialsourcefmt{$package}='generic';
   $specialsource{$package} = "Makefile|$standardsource";  
   &setup;
   &xchdir("$DEST/doc/$whichdocformat/$package");
   &buildfilelist;

   $inspatt=$standardins if ! $inspatt;
   &runins($inspatt);
   &buildfilelist;
   &dosource;
   &dotex;
   &dotype1;   
   killfiles($standardclean);
   &SYSTEM("mkdir -p $DEST/tex/latex/$package");
   &SYSTEM("mv $DEST/tex/generic/$package/*sty $DEST/tex/latex/$package");
   &SYSTEM("mv $DEST/doc/generic/$package/*cfg $DEST/tex/latex/$package");
}

# pst-geo specialities
# 
sub MAKEpstgeo {
   print "\t SPECIAL pst-geo $package starts\n";
   $standardtex = qq{^$package(Obj)?\.(tex|sty)};  # for pst-laboObj.tex
   $whichformat='generic';
   $whichdocformat='generic';
   $specialsourcefmt{$package}='generic';
   &setup;
   &xchdir("$DEST/doc/$whichdocformat/$package");
   -d <*/*/*/*/*/.> && &SYSTEM("$MV -f */*/*/*/* .");
   -d <*/*/*/*/.> && &SYSTEM("$MV -f */*/*/* .");
   -d <*/*/*/.> && &SYSTEM("$MV -f */*/* .");
   -d <*/*/.> && &SYSTEM("$MV -f */*/* .");
   -d <*/.> && &SYSTEM("$MV -f */* .");
   &SYSTEM("find -type d -print | xargs rmdir 2>/dev/null");
   &SYSTEM("find -type f -print >/tmp/find");
   &buildfilelist;

   $inspatt=$standardins if ! $inspatt;
   &runins($inspatt);
   &buildfilelist;
   &dosource;
   &dotex;
   &dotype1;   
   killfiles($standardclean);
   &SYSTEM("mkdir -p $DEST/tex/latex/$package");
   &SYSTEM("mv $DEST/tex/generic/$package/*sty $DEST/tex/latex/$package");
   &SYSTEM("mv $DEST/doc/generic/$package/*sty $DEST/tex/latex/$package");
   &SYSTEM("mv $DEST/doc/generic/$package/*cfg $DEST/tex/latex/$package");
}


sub MAKEfontinst {
chdir("$packagedir");
&runjob("mkdir -p $DEST/tex/latex/fontinst");
&runjob("mkdir -p $DEST/tex/fontinst");
&runjob("mkdir -p $DEST/source/fontinst");
&runjob("mkdir -p $DEST/doc/fontinst/base");
&runjob("$CP -r examples test $DEST/doc/fontinst/base");
&runjob("$CP -r doc/* README test $DEST/doc/fontinst/base");
&runjob("$CP -r source $DEST/source/fontinst/base");
&runjob("$CP -r latex/* $DEST/tex/latex/fontinst");
&runjob("$CP -r inputs/* $DEST/tex/fontinst");
}

sub MAKEpsnfss {
  # we use the psnfss.zip from the latex-tds project.
  # But we don't want the actual tfm/vf; TL has many more tfm's (in
  # different packages), and we don't want to mess with that.  So just
  # remove the fonts subdir -- except for the map files, which we do want.
  #
  print "\t SPECIAL $package omit fonts from latex-tds version\n";
  
  # Start with the usual straight copy.
  &MAKEcopy ();

  # Then remove the entire fonts tree.
  &xchdir ("$DEST/fonts");
  &SYSTEM ("rm -rf enc tfm vf");
}

sub MAKEcjk
{
  print "\t SPECIAL $package wholesale rearranging\n";
  #
  &setup ();
  #
  # start by removing the version number top-level directory.
  &xchdir ($DOCDIR);
  &SYSTEM ("$RM *.zip && $MV 4.8.?/* . && rmdir 4.8.?");
  #
  &xchdir ($DEST);
  #
  # move contrib into source subdir.
  &SYSTEM ("$MV $DOCDIR/contrib source/latex/cjk/");
  #
  # rename texinput to tex/latex/cjk.
  &SYSTEM ("rmdir tex/latex/cjk; $MV $DOCDIR/texinput tex/latex/cjk");
  #
  # rename texlive, contains modified KS/HLaTeX .fd files.
  my $ksl_dest = "tex/latex/cjk/contrib/hlatex-texlive";
  &xmkdir ($ksl_dest);
  &SYSTEM ("$MV $DOCDIR/texlive $ksl_dest");
  #
  # move utils into source subdir too, wht we have in
  # Build/source/texk/cjkutils is a tiny subset.
  &SYSTEM ("$MV $DOCDIR/utils source/latex/cjk/");
  #
  # remove the thaifont runtime files which we painfully package separately.
  # but leave other thaifont files here, not worth dealing.
  &SYSTEM ("rm -rf source/latex/cjk/utils/thaifont/texmf");
  #
  # We need the wadalab fd files.
  my $wada_dest = "tex/latex/cjk/contrib/wadalab";
  &xmkdir ($wada_dest);
  &SYSTEM ("$MV source/latex/cjk/contrib/wadalab/*.fd* $wada_dest/");
}

sub MAKEcmlgc
{
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
 &SYSTEM("rm -rf vtex");
 &MAKEflatten;
}

sub MAKEpict2e
{
 &setup;
 chdir("$DEST/doc/$whichdocformat/$package");
   &setup;
   chdir("$DEST/doc/$whichdocformat/$package");
   &buildfilelist;
# run the .ins files (if any) supplied
   $inspatt = $specialins{$package} || $standardins; 
   $Foundry = $specialfoundry{$package} || $standardfoundry; 
   &runins($inspatt);
# rebuild the list of files in the directory
 &SYSTEM("$MV pict2e-example.cfg pict2e.cfg");
   &buildfilelist;
   &dodvi;
# rebuild again, as we have .dvi files now
   &buildfilelist;
   &dotex;
   &dosource;
   &SYSTEM("rmdir $DEST/tex/$whichformat/$package 2> /dev/null");
   &SYSTEM("rmdir $DEST/source/$whichformat/$package 2> /dev/null");
   &SYSTEM("rmdir $DEST/doc/$whichdocformat/$package 2> /dev/null");
   killfiles($standardclean);
}


sub MAKEpictex
{
 &setup;
 chdir ($DOCDIR) || die "chdir($DOCDIR) failed: $!";
 &SYSTEM("rm -rf mathspic");  # separate package
 &SYSTEM("$MV addon/* .; rmdir addon");
 &donormal;
}



sub FLATTEN_PREHOOK_cm_super
{
  print "FLATTEN_PREHOOK_$package - remove dvipdfm map files\n";
  # We generate our own dvipdfm (not to mention pdftex) map files.
  &SYSTEM ("$RM -rf dvipdfm");
}

sub POSTfpl
{
  print "POST$package - rename README.source\n";
  &SYSTEM ("$MV README.source $DEST/source/fonts/fpl/README");
}

sub POSTglossaries
{
  print "POST$package - move .bat\n";
  my $wdir = "$TOPDEST/bin/win32";
  &SYSTEM ("mkdir -p $wdir");
  &SYSTEM ("$CP $DEST/scripts/glossaries/makeglossaries.bat $wdir/");
}

sub FLATTEN_PREHOOK_ibygrk
{
  print "FLATTEN_PREHOOK_$package - handle ibycus4.map\n";
  # ibygrk has two instances of the same file ibycus4.map; it is
  # both tex source and mf source.  the usual method cannot deal, of course.
  &SYSTEM ("$MV fonts/source/public/ibycus4/ibycus4.map .");
  &SYSTEM ("$RM tex/generic/ibycus4/ibycus4.map");
}

sub POSTibygrk
{
  print "POST$package - second copy of ibycus4.map\n";
  # after the ibygrk structure has been set up, copy ibycus4.map to the
  # tex dir.
  &SYSTEM ("cd $DEST && $CP fonts/source/public/ibygrk/ibycus4.map "
           . "tex/generic/ibygrk/ibycus4.map");
}

sub POSTimpatient
{
  print "POST$package - remove fr subdirectory\n";
  &SYSTEM ("$RM -r fr");
}

sub POSTinteractiveworkbook
{
  print "POST$package - mv .sty directory\n";
  my $dest = "$DEST/tex/latex/$package";
  &SYSTEM ("mkdir -p $dest");
  &SYSTEM ("$MV interactiveworkbook.sty/* $dest/");
  &SYSTEM ("rmdir interactiveworkbook.sty");
}

sub POSTknuth
{
  print "POST$package - rearranging for texmf-doc\n";
  &xchdir ("$DEST/doc");
  &xmkdir ("english");
  &SYSTEM ("$MV knuth english"); 
  &SYSTEM ("$MV ../source/knuth english/knuth/source");
  &xchdir ("english/knuth");
  #
  # remove nonfree.
  &SYSTEM ("$RM tex/texbook.tex mf/mfbook.tex");
  #
  # remove sources that are in build tree.
  &xchdir ("source");
  &SYSTEM ("rm -rf etc mf mfware tex/tex.web tex/trip* texware web/*.web");
}

sub POSTkoma
{
  print "POST$package - removing symlinks\n";
  &SYSTEM ("find $DEST -type l | xargs --no-run-if-empty rm");
}

sub POSTlatex2html
{
  print "POST$package - moving $package.perl to doc\n";
  my $dest = "$DEST/doc/latex/$package";
  &SYSTEM ("mkdir -p $dest");
  &SYSTEM ("$MV $DEST/scripts/latex2html/styles/$package.perl $dest");
}

sub POSTlibertine
{
  print "POST$package - remove duplicates, nosource docs";
  # has to be a post routine instead of moreclean because we have to
  # remove a file in a non-doc directory.
  # 
  # no source for doku.pdf.
  &SYSTEM ("$RM doc/fonts/libertine/libertinedoku.pdf");
  #
  # these files are in babel and/or ibyhyph.
  &SYSTEM ("$RM -rf tex/latex/libertine/babel");
}

sub POSTpgf
{
  print "POST$package - mv generic+latex directories\n";
  &SYSTEM ("cd $DEST && mkdir tex && mv context generic latex plain tex");
}

sub POSTpstcox
{
  print "POST$package - mv latex .sty, doc Gallery\n";
  &SYSTEM ("mkdir -p $DEST/tex/latex/$package");
  &SYSTEM ("mv -v $DEST/doc/generic/$package/*sty $DEST/tex/latex/$package");
  &xchdir ("$DEST/doc/generic/$package");
  &SYSTEM ("mkdir pst-coxeterp/");
  # oops, depends on find order
  &SYSTEM ("mv -v Gallery.tex pst-coxeterp?* pst-coxeterp/");
  &SYSTEM ("mv -v doc/pst-coxcoor/ pst-coxcoor");
  &SYSTEM ("mv -v pst-coxcoor?* pst-coxcoor");
}

sub POSTxecjk
{
  print "POST$package - capitalization, moving non-TDS\n";

  &xmkdir ("$DEST/source/xelatex");
  &SYSTEM ("$MV $DEST/utils/xeCJK $DEST/source/xelatex/xecjk");

  &SYSTEM ("$MV $DEST/tex/xelatex/xeCJK $DEST/tex/xelatex/xecjk");
  &SYSTEM ("$MV $DEST/doc/xelatex/xeCJK $DEST/doc/xelatex/xecjk");
  
  # the one in MAKEcopy doesn't get it because .../xecjk doesn't exist
  # yet.  Not worth a prehook, author should fix.
  &SYSTEM ("$MV $DEST/README $DEST/doc/xelatex/xecjk/README");
}

sub POSTxecyr
{
  print "POST$package - handling bat, moving language.dat.add from runtime\n";
  &SYSTEM ("$MV $DEST/tex/generic/xecyr/language.dat.add"
           . " $DEST/doc/xelatex/xecyr");

  my $wdir = "$TOPDEST/bin/win32";
  &xmkdir ($wdir);
  &SYSTEM ("$MV $DEST/bin/xecyr/*.bat $wdir/");
}

sub POSTxetex_pstricks
{
  print "POST$package - need tex/ level\n";
  &xchdir ($DEST);
  &xmkdir ("tex", "doc/generic/$package");
  &SYSTEM ("$MV README doc/generic/$package");
  &SYSTEM ("$MV generic xelatex xetex tex");
}


# Allow overrides.  In particular, CTAN can change some hashes to make
# packages with licenses that TL doesn't allow.
# 
# Put the config file "ctan2tds-config.pl" in the dir from which you 
# run this script, or better, set the environment variable "CTAN2TDS_CONFIG".
# 
sub readconfig
{
  my ($base,$dir,$ext) = fileparse ($0,'\.pl');

  my $configFileName = "$dir/$base-config.pl";
  $configFileName = $ENV{"CTAN2TDS_CONFIG"} || $configFileName;

  my $result;
  if (-f $configFileName) {
    my $err = "Error: CTAN config file $configFileName";
    $result = eval `cat $configFileName`; # like require, but no look in INC
    die "$err; evaluation in file failed: $@" 
        if $@;
    die "$err; yielded result that is false" 
        unless $result;
  } else {
    $result=1;
  }
  return $result;
}

# vim: set tabstop=8 shiftwidth=2 expandtab: