summaryrefslogtreecommitdiff
path: root/Jambase
blob: 3d046e43f920c0a541277ec9c6cd83133adba046 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
#
# /+\
# +\		Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
# \+/
#
# This file is part of Jam - see jam.c for Copyright information.
#

# The Copyright information in jam.c reads:
#
#/*
# * /+\
# * +\   Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
# * \+/
# *
# * This file is part of jam.
# *
# * License is hereby granted to use this software and distribute it
# * freely, as long as this copyright notice is retained and modifications
# * are clearly marked.
# *
# * ALL WARRANTIES ARE HEREBY DISCLAIMED.
# */

# MODIFIDED version of jam 2.5 Jambase, for the ArgyllCMS project by Graeme W. Gill.
#           These modifications are herebye licensed under the same conditions
#           as as the rest of Jam, as detailed above.
#           Moved to a "Normalized" scheme, where Jamfile UNIX style target paths
#			are converted to platform specific, Jamfile relative, Gristed/SEARCH/LOCATE
#			form internally. Creating the tree is simplified by eliminating the SubDir
#           rule. Better support for MingW, OS X. More comprehensive ruleset.
#           Renamed Jamrules to Jamtop.
#
# JAMBASE - jam 2.5 ruleset providing make(1)-like functionality
#
# Supports UNIX, NT, and VMS.
#
# Special targets defined in this file:
#
# all				- parent of first, shell, files, lib, exe
# first				- first dependent of 'all', for potential initialization
# shell				- parent of all Shell targets 
# files				- parent of all File targets
# lib				- parent of all Library targets
# exe				- parent of all Main targets
# dirs				- parent of all MkDir targets
# install			- parent of all Install targets
# clean				- removes all Shell, File, Library, and Main targets
# uninstall			- removes all Install targets
#		

# Rules defined by this file:
#
# As obj : source.s ;					.s -> .o
# Bulk dir : files ;					populate directory with many files
# Cc obj : src.c : flags : defines : hdrpaths 
#										.c -> .o
# C++ obj : src.cc : flags : defines : hdrpaths
#										.cc -> .o
# Clean clean : sources ;				remove sources with 'jam clean'
# File dest : source ;					copy file
# FileNoClean dest : source ;			copy file, but don't delete dest during clean
# FakeFile dest : source ;				Fudge to say dest is created with source
# Fortran obj.o : source.f ;			.f -> .o
# GenFile target : program args ;		make custom file
# GenFileND target : program args : extra_dependecies ;
#										make custom file, program dependent & args not
# GenFileNND target : program args : extra_dependecies ;
#                                       make custom file, program & args not dependent
# GenFileNNDnc target : program args : extra_dependecies ;
#                                       Same as GenFileNND but don't clean the target.
# CatToFile dest : strings ;			save the arguments to the file
# GuiBin image ;						Mark executable as GUI applications
#                                       (Needs to go before other declarations of image) 
# HardLink target : source ;			make link from source to target
# HdrRule source : headers ;			handle #includes
# InstallInto dir : sources ;			install any files
# InstallBin dir : sources ;			install binaries
# InstallLib dir : sources ;			install files
# InstallShLib dir : sources ;			install files
# InstallFile dir : sources ;			install files
# InstallMan dir : sources ;			install man pages
# InstallShell dir : sources ;			install shell scripts
# Lex source.c : source.l ;				.l -> .c
# Library library : sources : flags : defines : hdrpaths : objects
#										static library from compiled sources
# LibraryFromLibraries lib : libs ;		static library from static libraries
# LibraryFromObjects lib : objects ;	static library from objects
# LinkLibraries images : libraries ;	add static libraries onto Mains
# LinkObjects images : objects ;		add objects onto Mains
# LinkShLibraries images : shlibraries ;	add shared libraries onto Mains
# Main image : sources : flags : defines : hdrpaths : objects : libs : shlibs ;
# 										create exe from compiled sources
# MainsFromSources sources ;			create exes each from their source
# MainFromObjects image : objects : libs : shlibs ;
#										create executable from objects
# MainVariant image : sources : flags : defines : hdrpaths : objects : libs : shlibs ;
# 										create exe from compiled sources with separate named objs
# MainLinkFlags mains : flags ;			add linker flags for object
# MkDir dir ;							make a directory, if not there
# Mod target : mode ;					sets mode of file
# NDepends dest : source ;				make Normalized dependency
# NNoUpdate targ ;						create Normalized target if needed but never update it 
# NIncludes dest : source ;				make Normalized co-dependency
# Object object : sources : flags : defines : hdrpaths ; 	compile object from source
# ObjectCcFlags objects : flags ;		add compiler flags for object
# ObjectPrefCcFlags objects : flags ;	add preference compiler flags for object (overridable)
# ObjectC++Flags objects : flags ;		add compiler flags for object
# ObjectPrefC++Flags objects : flags ;	add preference compiler flags for object (overridable)
# ObjectDefines objects : defines ;		add defines for object
# ObjectHdrs objects : dirs ;			add include directories for object
# ObjectKeep objects ;					mark objects to be kept after library build
# Objects sources : flags : defines : hdrpaths 		compile sources
# PeerInclude dir ;						include peer Jamfile
# FindTop ; 							Set TOP by locating JAMTOP file above SUBDIR
# ProjTop d1 d2 .. ;					Set project TOP
# RmTemps target : sources ;			remove temp sources after target made
# Setuid images ;						mark executables Setuid
#	set SHLINKDEFFILE on for Windows to define exports using .def file.
#	set SHLINKSEARCHEXEPATH true on UNIX/OSX to have applications search exeutable location for it 
# ShLibrary shlib : source ;				link shared library from compiled sources
# ShLibraryFromObjects shlib : objects ;	link shared library from objects
# ShLibraryLibraries shlib : libraries ;	add static libraries onto shared libraries link
# ShLibraryObjects shlib : objects ;		add objects onto shared libraries link
# ShLibraryShLibraries shlib : shlibraries ;	add shared libraries onto shared libraries link
# SoftLink target : source ;			make symlink from source to target
# SubInclude dir ;						include sub Jamfile
# Shell exe : source ;					make a shell executable
# Undefines images : symbols ;			save undef's for linking
# UserObject object : source ;			handle unknown suffixes for Object
# Yacc source.c : source.y ;			.y -> .c
# Aswig : source.i ;					.i -> .h _i.c .hpp 
#
# Utility rules
#
# val = geton var : varname ;				return the value of varname on var 
# paths = NormPaths paths [ : dir ] ;		normalize a set of paths relative to SUBDIR or dir
# paths = NormSrcPaths paths [ : dir ] ;	NormPaths with SRCDIR
# paths = NormDstPaths paths [ : dir ] ;	NormPaths with DSTDIR
# paths = NormSrcTargets paths [ : dir ] ;	normalize source targets, set Grist NOMLOC SEARCH
# paths = NormDstTargets paths [ : dir ] ;	normalize destination targets, set Grist NOMLOC LOCATE
# paths = NormISrcTargets paths [ : dir ] ;	Same as NormSrcTargets but ignore SRCDIR
# paths = NormIDstTargets paths [ : dir ] ;	Same as NormDstTargets but ignore DSTDIR
#
# More utility rules that have no side effects :
#
# FAppendSuffix f1 f2 ... : $(SUF) ;	return $(<) with suffixes if no current suffixes
# FStripCommon v1 : v2 ;				strip common initial parts of v1 v2
# FReverse a1 a2 ... ;					return ... a2 a1 
# FDelEmpty a1 a2 ... ;					return a1 a2 ... with any empty elements deleted
#
# Variables:
#
# Sub-Jamfile build variables, optionaly set in each Sub-Jamfile. They will
# be picked up by subsequent rules that set target relationships and
# creation rules. They are added to any Parent-Jamfile variables,
# and become the Parent-Jamfile variables of any SubIncludes.
# Relative file/path variables are anchored by the Jamfile location.
#
# ASFLAGS      - Flags for the assembler.
# CCFLAGS      - Flags for the C compiler.
# C++FLAGS     - Flags for the C++ compiler.
# LINKFLAGS    - Flags for the executable linker.
# SHLINKFLAGS  - Flags for the shared library linker.
# HDRS         - Complile header search directories
# DEFINES      - Compile defines
# LINKOBJS     - Link extra objects
# LINKLIBS     - Link extra libraries
# LINKSHLIBS   - Link extra shared libraries
# SHLINKOBJS     - ShLibrary Linker extra objects
# SHLINKLIBS     - ShLibrary Linker extra libraries
# SHLINKSHLIBS   - ShLibrary Linker extra shared libraries
#
# Sub-directory preferred build flags, e.g. optimizations etc.  These will only
# have effect if not set by a parent Jamfile (ie. involked from a leaf Jamfile).
#
# PREF_ASFLAGS
# PREF_CCFLAGS
# PREF_C++FLAGS
# PREF_LINKFLAGS
# PREF_SHLINKFLAGS
#
# Parent-Jamfile build variables. These are the accumulated
# values from any Parent Jamfiles, and will be added to any
# Sub-Jamfile variables when a rule picks them up. 
# File/path variables will have been normalized.
#
# P_ASFLAGS      - Flags for the assembler.
# P_CCFLAGS      - Flags for the C compiler.
# P_C++FLAGS     - Flags for the C++ compiler.
# P_LINKFLAGS    - Flags for the executable linker.
# P_SHLINKFLAGS  - Flags for the shared library linker.
# P_HDRS         - Complile header search directories
# P_DEFINES      - Compile defines
# P_LINKOBJS     - Link extra objects
# P_LINKLIBS     - Link extra libraries
# P_LINKSHLIBS   - Link extra shared libraries
# P_SHLINKOBJS     - ShLibrary Linker extra objects
# P_SHLINKLIBS     - ShLibrary Linker extra libraries
# P_SHLINKSHLIBS   - ShLibrary Linker extra shared libraries
#
# Pre-defined values
#
# Pre-packaged flags that conceal platform dependence,
# and are used to set CCFLAGS/C++FLAGS/LINKFLAGS/SHLINLFLAGS etc.
#
#	CCOPTFLAG       - CC/C++ flag for optimization
#	CCDEBUGFLAG     - CC/C++ flag for debug
#	CCPROFFLAG	    - CC/C++ flag for performance profiling
#	CCSHOBJFLAG     - CC/C++ flag for compiling for a shared library (UNIX)
#
#	LINKOPTFLAG		- LINK flag for optimization of the binary/shared library
#	LINKDEBUGFLAG	- LINK flag to support debugging
#	LINKPROFFLAG	- LINK flag to support performance profiling
#	LINKSTRIPFLAG	- LINK flag to strip binary of any symbols
#
# Location variables:
#
# DSTDIR	- puts all products in a subdirectory of their nominated location.
#             Useful for storing variants in their own areas.                 
#
# SRCDIR    - Looks for all sources and Jamfiles in an alternate top level source
#             location. Useful for accessing a read only source repository, or
#             building a variant without copying all the sources.
#             Note that at least the project Jamtop must be in the location
#             that is the target for the build, and will most likely be where
#             SRCDIR is set. SRCDIR is the location of the sources relative
#             to where it is declared.
#             (Not currently useful for a shadow build repository where the source
#              is spread between the SRCDIR and the build dir, because Jam 2.5 fails
#              to look at SEARCH if LOCATE is set).
#
# =========================================================================
# ArgyllCMS Normalize mods:
#
# The main change is to locate and identify targets using their nominated location in the
# filesystem. This eliminates the need to create Grist, or manipulate SEARCH, LOCATE etc.
# when setting up a herachy of Jamfiles. 
#
# Whenever a path is provided as an argument to one of the public rules, its path is assumed
# to be relative to the Jamfile that it is declared in. [ The NormPaths/NormTargets rules do this. ]
# Naturally absolute paths are not affected by this.
# During execution this means that all files are translated to paths that are
# in a normalized form, with either an absolute path or one that is relative to
# the directory that Jam was involked in. For simplicity it is assumed that
# the Jamfile contains UNIX style paths, and these are converted to the
# platform specific form on normalization.
#
# For a target, the normalized directory is then stripped from the name and
# set as the Grist (path elements separated by !), and also set in the NOMLOC,
# LOCATE and SEARCH variables "on" the target.  This gives a target a unique
# identity for the whole of the build, determined by its nominated file system location.
# The NOMLOC variable is a way of recovering it's location without having the reverse
# the Grist strings.  The actual location of the target can then be varied by
# augmenting it's LOCATE and/or SEARCH variables.
#
# Any include file discovered by header scanning is searched for using the 
# search path that is expected to be used during compilation, and
# its nominated location resolved this way. Any headers that are not
# located this way or who's location isn't declared by another rule (the
# latter being typical when headers are being generated) will be marked as
# being in an __unknown__ directory and will not be scaned. Normally any
# header files located in the STDHDRS directories will not be scanned either.
#
# [ Typically headers will be __unknown__ if the STDHDRS directories do
#   not reflect the default paths actually searched by the compiler, or if a
#   header is not actually going to be #included because it is protected
#   by an #ifdef. ]

# Argyll Jambase internal implementation rules:

# IDs = _TargetIDs targpaths ;				return target ID's (gristed) from normalized paths
# path = DeNormTargs target ;				return the original path 
# CopyTarget dest : source ; 				duplicate a targets on NOMLOC LOCATE SEARCH variables.
# NotTargets vars ;							ensure variables aren't treated as LOCATE etc targets

# d1 d2 ... file = _SepPath path ;			separate a path into its components
# path = _DirName d1 d2 ... ;				combine components into a path
# d1 d2 .. = _RatPath d1 d2 .. 				rationalize a path
# d1 d2 .. = _RootPath d1 d2 .. : p1 p2 ... re-root a path
# paths = RatPaths paths ;					rationalize a set of paths
# paths = RootPaths dir : paths ;			re-root a set of paths
# targs = CreateIDstTargets targs : dir ;	create dest targets by locating targets in dir
# paths1/paths = CatPaths path1 : paths ; 	concatenate paths separated by a / 
# found = FindToRoot starting_dir : file ;	Try and locate file from directory up to root.

# FindTop ;		# Look for a default project file 

# DoInit ;									Do subdir initialization (done by JAMBASE)

# public write/read Variables:
#
# TRACESTDHDRS				# Normally false, set to true to trace system path #include file dependenicies

# public read only Variables:
#
# SUBDIR d1/d2/d3			# Current path from PWD to Jamfile
# TOP d1/d2/d3				# Current path from PWD to the project Jamtop

# internal variables
#
# _SUBDIR d1 d2 d3 ...		# Current path from PWD to Jamfile
# _TOP d1 d2 d3				# Current path from PWD to the project Jamtop

# - - - - - - - - - - - - - - -

# NOTE:	Cross compiling support :-
#	To fix this to support cross compilation, the setup needs to be
#	modularised into 3 parts, making them all rules that can be re-involked:
#	1) OS/Platform setup. System tools like copy, delete etc.
#	2) Compiler setup. Basic compiler syntax etc.
#	3) Target setup. Make this a rule, and allow switching
#	   target by involking the rule. This will be simpler to
#	   get working that per target 'on' variable (some
#	   things are currently broken for 'on' variables, such
#	   as library members, and it will be easier to do
#	   things such as switch compilers.

# - - - - - - - - - - - - - - -


# Brief review of the jam language:
#
# Statements:
#		rule RULE - statements to process a rule
#		actions RULE - system commands to carry out target update
#
# Modifiers on actions:
#		together - multiple instances of same rule on target get executed
#				   once with their sources ($(>)) concatenated
#		updated - refers to updated sources ($(>)) only
#		ignore - ignore return status of command
#		quietly - don't trace its execution unless verbose
#		piecemeal - iterate command each time with a small subset of $(>)
#		existing - refers to currently existing sources ($(>)) only
#		bind vars - subject to binding before expanding in actions
#
# Special rules:
#		Always - always build a target
#		Depends - builds the dependency graph
#                 NOTE: can have only one $(<), or parallel builds stuff up!!
#                       Use FakeFile to work around the problem.
#		Echo - blurt out targets on stdout
#		Exit - blurt out targets and exit
#		Includes - marks sources as headers for target (a codependency)
#		NoCare - don't panic if the target can't be built
#		NoUpdate - create the target if needed but never update it 
#		NotFile - ignore the timestamp of the target (it's not a file)
#		Temporary - target need not be present if sources haven't changed
#
# Special variables set by jam:
#		$(<) - targets of a rule (to the left of the :)
#		$(>) - sources of a rule (to the right of the :)
#		$(xxx) - true on xxx (UNIX, VMS, NT, OS2, MAC)
#		$(OS) - name of OS - varies wildly
#		$(JAMVERSION) - version number (2.5)
#
# Special variables used by jam:
#		SEARCH - where to find something (used during binding and actions)
#		LOCATE - where to plop something not found with SEARCH
#		HDRRULE - rule to call to handle include files
#		HDRSCAN - egrep regex to extract include files
#
# Special targets:
#		all - default if none given on command line
#

# for perforce use -- jambase version

JAMBASEDATE = 2008.03.26 ;

# Initialize variables
#

# ===========================================================
#
# OS specific variable settings
#

if $(NT)
{
	MV				?= move /y ;
	CP				?= copy ;
	RM				?= del /f/q ;
	RMDIR			?= rmdir /s/q ;
	SLASH			?= \\ ;
	SUFLIB			?= .lib ;
	SUFSHLIB		?= .dll ;
	SUFIMPLIB		?= .lib ;
	SUFOBJ			?= .obj ;
	SUFEXE			?= .exe ;
	SUFSH			?= .bat ;
	CCSHOBJFLAG		?= ;

	if $(BCCROOT)
	{
		AR				?= tlib /C /P64 ;
		CC				?= bcc32 ;
		CCFLAGS			?= -v -w- -q -DWIN -tWR -tWM -tWC ;
		C++				?= $(CC) ;
		C++FLAGS		?= $(CCFLAGS) -P ;
		LINK			?= $(CC) ;
		LINKFLAGS		?= ;
		STDLIBPATH		?= $(BCCROOT)\\lib ;
		STDHDRS			?= $(BCCROOT)\\include ;
		NOARSCAN		?= true ;
	}
	else if $(MingW) || $(MINGW)
	{
		# We need to do something about adding -Wl,-subsystem,windows
		# if WinMain is being used ? (it defaults to console)

		MINGW           ?= $(MingW) ; 
		TPFX             = "" ;

		if [ GLOB $(MINGW)/bin : x86_64-w64-mingw32-gcc.exe ] {
			MINGW64 = $(MINGW) ;
        }
		
		# This doesn't work on a 32 bit system because we're cross
		# compiling and need to create build system exe's
		# (tiff/mkversion.exe, imdi/imdi_make.exe
		# Will using -m32 for local exe's fix this ?
		# What is multi-lib option ???
		if $(MINGW64) {
			ECHO "Compiler is MingW for 64 bit target" ;
			TARGET64     = true ;
			TPFX         = x86_64-w64-mingw32- ;
			MINGW64_LIB32 = $(MINGW)/mingw/lib32 ;
		} else {
			ECHO "Compiler is MingW for 32 bit target" ;
		}


		# Basic C/C++ tools
		AR				?= $(TPFX)ar rusc ;
		AS				?= $(TPFX)as ;
		CC				?= $(TPFX)gcc ;
		CCFLAGS			?= -DNT -mwin32 -pipe ;
		C++				?= $(CC) ;
		C++FLAGS		?= $(CCFLAGS) ;

		OLELIBS			?= -loleaut32 -luuid ;
		BASELIBS		?= -lstdc++ -lgcc -lodbc32 -lwsock32 ;
#		WINLIBS			?= -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32
#						   -lodbc32 -ladvapi32 -lodbc32 -lwsock32 -lopengl32
#		                   -lglu32 -lshlwapi -lsetupapi ;
		WINLIBS			?= -lshlwapi -lsetupapi -lole32 -lws2_32 -lpsapi -lversion ;
		GUILIBS			?= -lgdi32 -lmscms ;

		LINK			?= $(TPFX)g++ ;		# In case we link to C++ files
		LINKFLAGS		?= -static ;
		SHLINKFLAGS		?= ;
		STDLIBS			?= -lm $(OLELIBS) $(WINLIBS) $(GUILIBS) ;
		SHSTDLIBS		?= $(STDLIBS) ;

		STDHDRS			?= $(MINGW)\\include ;	

		# Not sure whether linker -mconsole or -mwindow are needed ??

		# Allow setting of flags, independent of compiler
		DEFFLAG			?= -D ;
		UNDEFFLAG		?= -U ;
		CCOPTFLAG		?= -O3 ;
		if $(PROCESSOR_LEVEL) = 15 
		{	# -mtune seems faster than -march !!!
#			CCOPTFLAG	+= -mtune=pentium4 ;
#			CCOPTFLAG	+= -mtune=prescott ;
			CCOPTFLAG	+= -mtune=nocona ;	# portable code for Pentium4 640
#			CCOPTFLAG	+= -march=nocona -mfpmath=sse -msse3 ; # non-portable

		}

		CCDEBUGFLAG		?= -g ;				# default (TABS? DWARF2 ?) format
		CCPROFFLAG		?= -pg ;
		LINKDEBUGFLAG	?= -g ;
		LINKPROFFLAG	?= -pg ; 
		LINKOPTFLAG		?= -s -O ;			# Affects creating .so's ??
		LINKSTRIPFLAG	?= -s ;	

		# Other tools
		AWK				?= awk ;
		SED				?= sed ;

#		YACC			?= yacc ;
#		YACCFLAGS		?= -d ;
#		YACCFILES		?= y.tab ;

		YACC			?= bison -y ;
		YACCGEN			?= .c ;
		YACCFILES		?= y.tab ;
		YACCFLAGS		?= -d ;
	}
	else if $(MSVC)		# 
	{
		ECHO "Compiler is VC++ 16 bit" ;
		AR				?= lib /nologo ;
		CC				?= cl /nologo ;
		CCFLAGS			?= /D \"WIN\" ;
		C++				?= $(CC) ;
		C++FLAGS		?= $(CCFLAGS) ;
		LINK			?= $(CC) ;
		LINKFLAGS		?= ;
		STDLIBS			?= 
							$(MSVC)\\lib\\mlibce.lib
							$(MSVC)\\lib\\oldnames.lib
							;
		NOARSCAN		?= true ;
		STDHDRS			?= $(MSVC)\\include ;
		DEFFLAG		 	?= /D ;						
		UNDEFFLAG		?= "/u _" ;
	}
	else if $(TARGET_ARCH)
	{
		# Intel C++ compiler (ICL) 

		# No IA64 dir
		local I ; I = "" ;

		AR				?= lib /NOLOGO ;
		AS				?= masm386 ;
		CC              ?= icl /nologo ; 
		CCFLAGS			?= /DNT /MD ;		# DLL compatible build by default

		C++				?= $(CC) ;
		C++FLAGS		?= $(CCFLAGS) /GX ;		# GX enables syncronous exception handling
		LINK			?= xilink /nologo ; 
		LINKOUTFLAG		?= /out: ;
		LINKFLAGS       ?= ; 		# iclvars.bat [arch] sets this up

		SHLINKFLAGS		?= ;

		STDLIBS			?= 
						oldnames.lib
						kernel32.lib 
						advapi32.lib		
						user32.lib		
						mscms.lib		
						gdi32.lib		 
						shlwapi.lib		 
						shell32.lib		 
						setupapi.lib
						ole32.lib
						oleaut32.lib
						ws2_32.lib
						Wbemuuid.lib
						;
		SHSTDLIBS		?= $(STDLIBS) ;
		LINKFLAG		?= ;						
		STDHDRS			?= $(ICPP_COMPILER14)\\Include ;
		DEFFLAG		 	?= /D ;				
		UNDEFFLAG		?= /U ;
		CCOPTFLAG		?= /O3 ; 

		if $(MSVCVER) = 6 {
			CCDEBUGFLAG		?= /Od /Z7 ;		# Include debugging into in each object		
			CCPROFFLAG		?= /Od /Z7 ;
			LINKDEBUGFLAG	?= /DEBUGTYPE:BOTH /DEBUG /PDB:NONE ;		
		} else {
			CCDEBUGFLAG		?= /Od /Zi ;		# /Zi creates debugging database
			CCPROFFLAG		?= /Od /Zi ;
			LINKDEBUGFLAG	?= /DEBUG ;
		}
		LINKPROFFLAG	?= /PROFILE $(LINKDEBUGFLAG) ;		
		LINKOPTFLAG		?= /OPT:REF ;	
		LINKSTRIPFLAG	?= ;
		YACC			?= bison -y ;
		YACCGEN			?= .c ;
		YACCFILES		?= y.tab ;
		YACCFLAGS		?= -d ;
	}
	else if $(MSVCNT) || $(MSVCDIR) || $(MSVCDir) || $(VCINSTALLDIR)
	{
		# Visual C++ 8.0/9.0/10.0/11.0/12.0 uses VCINSTALLDIR
		# We assume VC++ Express + XP32 SDK has been setup

		if $(VCINSTALLDIR) {
			MSVCNT		?= $(VCINSTALLDIR) ;		
		} else if $(MSVCDir) {
			MSVCNT		?= $(MSVCDir) ;		
		} else {			# Visual C++ 6.0 uses MSVCDIR
			MSVCNT		?= $(MSVCDIR) ;		
		}

		if [ MATCH 12\\.(.*) : $(VisualStudioVersion) ] {
			ECHO "Compiler is VC++12 32 bit" ;
			MSVCVER     = 12 ;
		} else if [ MATCH 11\\.(.*) : $(VisualStudioVersion) ] {
			ECHO "Compiler is VC++11 32 bit" ;
			MSVCVER     = 11 ;
		} else if [ MATCH (.*)VC\\+\\+10(.*) : $(MSVCNT) ] {
			ECHO "Compiler is VC++10 32 bit" ;
			MSVCVER     = 10 ;
		} else if [ MATCH (.*)VC\\+\\+9(.*) : $(MSVCNT) ] {
			ECHO "Compiler is VC++9 32 bit" ;
			MSVCVER     = 9 ;
		} else if [ MATCH (.*)VC\\+\\+8(.*) : $(MSVCNT) ] {
			ECHO "Compiler is VC++8 32 bit" ;
			MSVCVER     = 8 ;
		} else {
			ECHO "Compiler is VC++6 32 bit" ;
			MSVCVER     = 6 ;
		}

		# Add the SDK include and lib if it is present
		if $(MSSdk) {
			MSNTSDK ?= $(MSSdk) ;
		} else if $(MSSDK) {
			MSNTSDK ?= $(MSSDK) ;
		} else if $(MSVCNT) {
			MSNTSDK ?= $(MSVCNT) ;
		}

		# bury IA64 in the path for the SDK ???
		# (but MSSDK already has this ?
#		local I ; if $(CPU) = "IA64" { I = ia64\\ ; } else { I = "" ; }
		local I ; I = "" ;

		AR				?= lib /NOLOGO ;
		AS				?= masm386 ;
		CC				?= cl /nologo ;
		CCFLAGS			?= /DNT /MD ;		# DLL compatible build by default
		if $(MSVCVER) >= 8 {
			CCFLAGS		+= /D_CRT_SECURE_NO_DEPRECATE=1
                           /D_CRT_NONSTDC_NO_DEPRECATE=1 ;
		}
		C++				?= $(CC) ;
		C++FLAGS		?= $(CCFLAGS) /GX ;		# GX enables syncronous exception handling
		LINK			?= link /nologo ;
		LINKOUTFLAG		?= /out: ;
		LINKFLAGS		?= /INCREMENTAL:NO /LIBPATH:$(MSNTSDK)\\lib\\$(I) ;
		SHLINKFLAGS		?= ;

		STDLIBS			?= 
						oldnames.lib
						kernel32.lib 
						advapi32.lib		
						user32.lib		
						mscms.lib		
						gdi32.lib		 
						shlwapi.lib		 
						shell32.lib		 
						setupapi.lib
						ole32.lib
						oleaut32.lib
						ws2_32.lib
						Wbemuuid.lib
						Version.lib
						;
		if $(MSVCVER) >= 8 {
			STDLIBS += psapi.lib ;
		}

		SHSTDLIBS		?= $(STDLIBS) ;
		LINKFLAG		?= ;						
		STDHDRS			?= $(MSNTSDK)\\Include ;
		DEFFLAG		 	?= /D ;				
		UNDEFFLAG		?= /U ;
		CCOPTFLAG		?= /Ox ;		# MSVC9 doesn't understamd GB, G6 ?
		if $(MSVCVER) = 6 {
			CCDEBUGFLAG		?= /Od /Z7 ;		# Include debugging into in each object		
			CCPROFFLAG		?= /Od /Z7 ;
			LINKDEBUGFLAG	?= /DEBUGTYPE:BOTH /DEBUG /PDB:NONE ;		
		} else {
			CCDEBUGFLAG		?= /Od /Zi ;		# /Zi creates debugging database
			CCPROFFLAG		?= /Od /Zi ;
			LINKDEBUGFLAG	?= /DEBUG ;
		}
		LINKPROFFLAG	?= /PROFILE $(LINKDEBUGFLAG) ;		
		LINKOPTFLAG		?= /OPT:REF ;	
		LINKSTRIPFLAG	?= ;
		YACC			?= bison -y ;
		YACCGEN			?= .c ;
		YACCFILES		?= y.tab ;
		YACCFLAGS		?= -d ;
	}
	else
	{
		EXIT On NT, set BCCROOT, MINGW, MSVCDIR, MSVCNT, MSVC or VCINSTALLDIR to the root
				of the Borland, GCC or Microsoft directories. ;
	}
}
else if $(OS2)
{
	WATCOM			?= $(watcom) ;
	 
	if ! $(WATCOM)
	{
		Exit On OS2, set WATCOM to the root of the Watcom directory. ;
	}

	AR				?= wlib ;
	BINDIR			?= \\os2\\apps ;
	CC				?= wcc386 ;
	CCFLAGS			?= /zq /DOS2 /I$(WATCOM)\\h ; # zq=quiet
	C++				?= wpp386 ;
	C++FLAGS		?= $(CCFLAGS) ;
	CP				?= copy ;
	DOT				?= . ;
	DOTDOT			?= .. ;
	LINK			?= wcl386 ;
	LINKFLAGS		?= /zq ; # zq=quiet
	STDLIBS			?= ;
	MV				?= move ;
	NOARSCAN		?= true ;
	RM				?= del /f ;
	SLASH			?= \\ ;
	STDHDRS			?= $(WATCOM)\\h ;
	SUFEXE			?= .exe ;
	SUFSH			?= .bat ;
	SUFLIB			?= .lib ;
	SUFOBJ			?= .obj ;
	DEFFLAG		 	?= /D ;				
	UNDEFFLAG		?= "/u _" ;

}
else if $(VMS)
{
	C++				?= cxx ;
	C++FLAGS		?= ;
	CC				?= cc ;
	CCFLAGS			?= ;
	CHMOD			?= set file/prot= ;
	CP				?= copy/replace ;
	CRELIB			?= true ;
	DOT				?= [] ;
	DOTDOT			?= [-] ;
	EXEMODE			?= (w:e) ;
	FILEMODE		?= (w:r) ;
	HDRS			?= ;
	LINK			?= link ;
	LINKFLAGS		?= "" ;
	STDLIBS			?= ;
	MKDIR			?= create/dir ;
	MV				?= rename ;
	RM				?= delete ;
	RUNVMS			?= mcr ;
	SHELLMODE		?= (w:er) ;
	SLASH			?= . ;
	STDHDRS			?= decc$library_include ;
	SUFEXE			?= .exe ;
	SUFSH			?= .bat ;
	SUFLIB			?= .olb ;
	SUFOBJ			?= .obj ;

	switch $(OS) 
	{
		case OPENVMS : CCFLAGS ?= /stand=vaxc ;
		case VMS	 : STDLIBS ?= sys$library:vaxcrtl.olb/lib ;
	}
}
else if $(MAC)
{
	local OPT ;
	
	CW		?= "{CW}" ;

	MACHDRS ?=
			"$(UMACHDRS):Universal:Interfaces:CIncludes"
			"$(CW):MSL:MSL_C:MSL_Common:Include"
			"$(CW):MSL:MSL_C:MSL_MacOS:Include" ;

	MACLIBS ?=
			"$(CW):MacOS Support:Universal:Libraries:StubLibraries:Interfacelib"
			"$(CW):MacOS Support:Universal:Libraries:StubLibraries:Mathlib" ;

	MPWLIBS ?= 
			"$(CW):MacOS Support:Libraries:Runtime:Libs:MSL_MPWCRuntime_PPC.lib"
			"$(CW):MSL:MSL_C:MSL_MacOS:Lib:PPC:MSL_C_PPC_MPW.Lib" ;

	MPWNLLIBS ?= 
			"$(CW):MacOS Support:Libraries:Runtime:Libs:MSL_MPWCRuntime_PPC.lib"
			"$(CW):MSL:MSL_C:MSL_MacOS:Lib:PPC:MSL_C_PPC_MPW(NL).Lib" ;
			
	SIOUXHDRS ?= ;
	
	SIOUXLIBS ?= 
			"$(CW):MacOS Support:Libraries:Runtime:Libs:MSL_Runtime_PPC.lib"
			"$(CW):MSL:MSL_C:MSL_MacOS:Lib:PPC:MSL_SIOUX_PPC.Lib" 
			"$(CW):MSL:MSL_C:MSL_MacOS:Lib:PPC:MSL_C_PPC.Lib" ;

	C++				?= mwcppc ;
	C++FLAGS		?= -w off ;
	CC				?= mwcppc ;
	CCFLAGS			?= -w off ;
	CP				?= duplicate -y ;
	DOT				?= ":" ;
	DOTDOT			?= "::" ;
	HDRS			?= $(MACHDRS) $(MPWHDRS) ;
	LINK			?= mwlinkppc ;
	LINKFLAGS		?= -mpwtool -warn ;								
	STDLIBS			?= $(MACLIBS) $(MPWLIBS) ;								
	SHSTDLIBS		?= $(STDLIBS) ;
	MKDIR			?= newfolder ;
	MV				?= rename -y ;
	NOARSCAN		?= true ;
	RM				?= delete -y ;
	SLASH			?= ":" ;
	STDHDRS			?= ; 
	SUFLIB			?= .lib ;
	SUFOBJ			?= .o ;
}
else if $(OS) = BEOS && $(OSPLAT) = PPC
{
	AR				?= mwld -xml -o ;
	BINDIR			?= /boot/home/config/bin ;
	CC				?= mwcc ;
	CCFLAGS			?= -nosyspath ;
	C++				?= $(CC) ;
	C++FLAGS		?= -nosyspath ;
	CHMOD			?= chmod ;
	CHGRP			?= chgrp ;
	CHOWN			?= chown ;
	FORTRAN			?= "" ;
	LEX				?= flex ;
	LIBDIR			?= /boot/home/config/lib ;
	LINK			?= mwld ;
	LINKFLAGS		?= "" ;
	MANDIR			?= /boot/home/config/man ;
	NOARSCAN		?= true ;
	RANLIB			?= ranlib ;
	STDHDRS			?= /boot/develop/headers/posix ;
	YACC			?= bison -y ;
	YACCGEN			?= .c ;
	YACCFILES		?= y.tab ;
	YACCFLAGS		?= -d ;
}
else if $(OS) = BEOS 
{
	BINDIR			?= /boot/home/config/bin ;
	CC				?= gcc ;
	C++				?= $(CC) ;
	CHMOD			?= chmod ;
	CHGRP			?= chgrp ;
	CHOWN			?= chown ;
	FORTRAN			?= "" ;
	LEX				?= flex ;
	LIBDIR			?= /boot/home/config/lib ;
	LINK			?= gcc ;
	MANDIR			?= /boot/home/config/man ;
	NOARSCAN		?= true ;
	RANLIB			?= ranlib ;
	STDHDRS			?= /boot/develop/headers/posix ;
	YACC			?= bison -y ;
	YACCGEN			?= .c ;
	YACCFILES		?= y.tab ;
	YACCFLAGS		?= -d ;
}
else if $(UNIX)
{
	switch $(OS)
	{
	case AIX :
		STDLIBS			?= -lbsd ;

	case AMIGA :
		CC				?= gcc ;
		YACC			?= bison -y ;

	case CYGWIN :		
		CC				?= gcc ;
		CCFLAGS			+= -D__cygwin__ ;
		LEX				?= flex ;
		JAMSHELL		?= sh -c ;
		RANLIB			?= "" ;
		SUFEXE			?= .exe ;
		YACC			?= bison -y ;

	case DGUX :
		RANLIB			?= "" ;
		RELOCATE		?= true ;

	case HPUX :
		RANLIB			?= "" ;

	case INTERIX :
		CC				?= gcc ;
		JAMSHELL		?= sh -c ;
		RANLIB			?= "" ;

	case IRIX :
		RANLIB			?= "" ;

	case MPEIX :
		CC				?= gcc ;
		C++				?= gcc ;
		CCFLAGS			+= -D_POSIX_SOURCE ;
		HDRS			+= /usr/include ;
		RANLIB			?= "" ; 
		NOARSCAN		?= true ;
		NOARUPDATE		?= true ;

	case MVS :
		RANLIB			?= "" ; 

	case NEXT :
		AR				?= libtool -o ;
		RANLIB			?= "" ;

	case MACOSX :
#		AR			  	?= libtool -o ;
		AR			  	?= ar rusc ;
		C++				?= c++ ;
		MANDIR			?= /usr/local/share/man ;
		RANLIB		  	?= "" ;
		SUFSHLIB		?= .dylib ;
		SUFIMPLIB		?= .dylib ;

	case NCR :
		RANLIB			?= "" ;

	case PTX :
		RANLIB			?= "" ;

	case QNX :
		AR				?= wlib ;
		CC				?= cc ;
		CCFLAGS			?= -Q ;		# quiet
		C++				?= $(CC) ;
		C++FLAGS		?= -Q ;		# quiet
		LINK			?= $(CC) ;
		LINKFLAGS		?= -Q ;		# quiet
		NOARSCAN		?= true ;
		RANLIB			?= "" ;

	case SCO :
		RANLIB			?= "" ;
		RELOCATE		?= true ;

	case SINIX :
		RANLIB			?= "" ;

	case SOLARIS :
		RANLIB			?= "" ;
		AR				?= "/usr/ccs/bin/ar ru" ;

	case UNICOS :
		NOARSCAN		?= true ;
		CCOPTFLAG		?= -O0 ;

	case UNIXWARE :
		RANLIB			?= "" ;
		RELOCATE		?= true ;
	}

	# UNIX defaults

	CCFLAGS			?= -DUNIX -D_THREAD_SAFE -pipe ;
	CCOPTFLAG		?= -O2 ;		
	CCDEBUGFLAG		?= -g ;		
	CCPROFFLAG		?= ;		
	CCSHOBJFLAG		?= -fPIC ;			# Position independent is better for ShLibrary
	C++FLAGS		?= $(CCFLAGS) ;
	CHMOD			?= chmod ;
	CHGRP			?= chgrp ;
	CHOWN			?= chown ;
	LEX				?= lex ;
	LINKFLAGS		?= ;
	LINKOPTFLAG		?= -O ;				# Affects creating .so's
	LINKSTRIPFLAG	?= -s ;
	LINKDEBUGFLAG	?= ;
	LINKPROFFLAG	?= ;
	SHLINKFLAGS		?= ;					# Flags for creation of shared library
	STDLIBS			?= -lm -lpthread ;
	SHSTDLIBS		?= $(STDLIBS) ;
	LINKFLAG		?= -l ;
	RANLIB			?= "" ;
	YACC			?= yacc ;
	YACCGEN			?= .c ;
	YACCFILES		?= y.tab ;
	YACCFLAGS		?= -d ;

	HDRS			?= /usr/local/include ;

	# Add some good defaults for OS X
	if $(OS) = MACOSX {
		CCFLAGS   		+= -Wno-sign-compare ;		# supress new gcc4 warnings ?
		CCFLAGS   		+= -fpascal-strings ;		# for compatibility with the OSX API
		LINKFLAGS 		+= -framework Carbon ;		# default for .c
		LINKFLAGS       += -framework Cocoa ;		# default for .m
	}

	# Make things work on 64 bit Linux
	# Because HOSTTYPE is not normally exported, check the uname() result
	if ! $(HOSTTYPE) {
		HOSTTYPE = $(JAMUNAME[1]) ;
	}

	if $(HOSTTYPE) = x86_64 
	 || $(HOSTTYPE) = x86_64-linux
	 || $(HOSTTYPE) = amd64 {
		ECHO "We're on a 64 bit host" ;
		HOST64     = true ;
		CCFLAGS	   += -m64 ;
		C++FLAGS   += -m64 ;
	}

	# Adding --hash-style=sysv to the compiler options
	# might improve Linux compatibility with FC5 ?
}

#
# General defaults; a lot like UNIX
#

	AR				?= ar rusc ;
	AS				?= as ;
	ASFLAGS			?= ;
	AWK				?= awk ;
	BINDIR			?= /usr/local/bin ;
	C++				?= cc ;
	C++FLAGS		?= ;
	CC				?= cc ;
	CCFLAGS			?= ;
	CP				?= cp -f ;
	CRELIB			?= ;
	DOT				?= . ;
	DOTDOT			?= .. ;
	EXEMODE			?= 755 ;
	FILEMODE		?= 644 ;
	FORTRAN			?= f77 ;
	FORTRANFLAGS	?= ;
	HDRS			?= ;
	INSTALLGRIST	?= installed ;
	JAMFILE			?= Jamfile ;
	JAMTOP			?= Jamtop ;
	LEX				?= ;
	LIBDIR			?= /usr/local/lib ;
	LINK			?= $(CC) ;
	LINKFLAGS		?= ;
	SHLINKFLAGS		?= ;
	STDLIBS			?= ;
	SHSTDLIBS		?= $(STDLIBS) ;
	LINKOUTFLAG	 	?= "-o " ;		
	LN				?= ln ;
	MANDIR			?= /usr/local/man ;
	MKDIR			?= mkdir ;
	MV				?= mv -f ;
	RCP				?= rcp ;
	RM				?= rm -f ;
	RMDIR			?= $(RM) ;
	RSH				?= rsh ;
	SED				?= sed ;
	SHELLHEADER		?= "#!/bin/sh" ;
	SHELLMODE		?= 755 ;
	SLASH			?= / ;
	STDHDRS			?= /usr/include ;
	SUFEXE			?= "" ;
	SUFSH			?= .sh ;
	SUFLIB			?= .a ;
	SUFSHLIB		?= .so ;
	SUFIMPLIB		?= .so ;
	SUFOBJ			?= .o ;

	DEFFLAG		 	?= -D ;				
	UNDEFFLAG		?= -U ;
	YACC			?= ;
	YACCGEN			?= ;
	YACCFILES		?= ;
	YACCFLAGS		?= ;

	HDRPATTERN = 
				"^[		 ]*#[		 ]*include[		 ]*[<\"]([^\">]*)[\">].*$" ;

	OSFULL = $(OS)$(OSVER)$(OSPLAT) $(OS)$(OSPLAT) $(OS)$(OSVER) $(OS) ;


# ===========================================================

#
# Base dependencies - first for "bootstrap" kinds of rules
#

Depends all : shell files lib exe obj ;
Depends all shell files lib exe obj install : first ;
NotFile all first shell files lib exe obj dirs clean install uninstall ;
Always clean uninstall ;

# ===========================================================
# ArgyllCMS Jambase building blocks:

# Allow returning of a targets "on" variable 
# Only the first variable in the list "on" variable is retrieved
# ret = geton target : variable ;
rule noop { return $(<) ; }
rule geton {
	local _rv ;
	_rv = [ on $(<[1]) noop $($(>)) ] ;
	return $(_rv) ;
}

# Separate a single path into it's components, irrespective of
# whether a MSWindows or UNIX path separator is used.
# d1 d2 ... file = _SepPath path ; 
rule _SepPath
{
#Echo "_SepPath called with = '" $(<[1]) "'" ;

	local _in = /$(<[1]) ;		# leading / is to detect absolute path
	local split  = true ;
	local _out = ;

	if ! $(<) {
#Echo "_SepPath returning '" "" "'" ;
		return $(<) ;
	}

	split = [ MATCH (.*)[/\\](.*) : $(_in) ] ;
	while $(split) {
#Echo "Split = '" $(split[1]) "' and '" $(split[2]) "'" ;
		_out = $(split[2]) $(_out) ;
		_in = $(split[1]) ;
		split = [ MATCH (.*)[/\\](.*) : $(_in) ] ;
	}
#Echo "After slplitting got '" $(_in) "' out '" $(_out) "'" ;

	if $(_in) != ""  {		# No leading /
#Echo "Setting _out to '" $(_in) "' plus '" $(_out) "'" ;
		_out = $(_in) $(_out) ;
	}

#Echo "_SepPath initial sep =" $(_out) ;

	# Deal with DOS drive letters
	if $(NT) {
		switch $(_out[1]) {
			case *:* : {
				split = [ MATCH (.*)[:](.*) : $(_out[1]) ] ;
				if $(split[2]) != "" {
					_out = $(split[1]): $(split[2]) $(_out[2-]) ;
				} else {
					_out = $(split[1]): $(SLASH) $(_out[2-]) ;
				}
			}
		}
#Echo "_SepPath after DOS letters _out =" $(_out) ;
	}

	# Make sure leading / is in the correct form 
	if $(_out[1]) = "/" || $(_out[1]) = "\\" {
		_out = $(SLASH) $(_out[2-]) ;
	} 

#Echo "_SepPath returning _out =" $(_out) ;

	return $(_out) ;
}

# Turn a sequence of directories into a directory path.
# Opposite of _SepPath
# path = _DirName d1 d2 ... ;
rule _DirName
{
	local _in = $(<) ;
	local _out = "" ;

#Echo "_DirName got '" $(_in) "'" ;

	# Deal with DOS drive letters
	if $(NT) {
		switch $(_in[1]) {
			case *:* : {
#Echo "_DirName match x:" ;
				_out = $(_in[1]) ;
				_in = $(_in[2-]) ;
			}
		}
#Echo "_DirName _in = '" $(_in) "' out = '" $(_out) "'" ;
	}

	# Deal with absolute path
	if $(_in[1]) = "/" || $(_in[1]) = "\\" {
		_out = $(_out)$(SLASH) ;
		_in = $(_in[2-]) ;
#Echo "_DirName abs in = '" $(_in) "' out = '" $(_out) "'" ;
	}

	while $(_in) {
		_out = $(_out)$(_in[1]) ;
		_in = $(_in[2-]) ;
#Echo "_DirName in = '" $(_in) "' out = '" $(_out) "'" ;
		if $(_in) {
			_out = $(_out)$(SLASH) ;
		}
#Echo "_DirName sep in = '" $(_in) "' out = '" $(_out) "'" ;
	}

#Echo "_DirName returning '" $(_out) "'" ;
	return $(_out) ;
}

# Rationalize a path (ie. cancell dirs & .. )
# Currently paths that cancel out return " ".
# d1 d2 .. file = _RatPath d1 d2 .. file ; 
rule _RatPath
{
	local _in = $(<) ;
	local _rio = ;		# reversed intermediate output
	local _out = ;
	local _gotdot = ;	# There was a dot in the input path
	local _first = ;	# Fixed first elements 

#Echo "_RatPath called with '" $(_in) "'" ;
	
	# Deal with DOS drive letters
	if $(NT) {
		switch $(_in[1]) {
			case *:* : {
				_first = $(_first) $(_in[1]) ;
				_in = $(_in[2-]) ;
			}
		}
#Echo "_RatPath got first '" $(_first) "' in = '" $(_in) "'" ;
	}

	# Deal with absolute path or single dot
	if $(_in[1]) = / || $(_in[1]) = \\ {
		_first = $(_first) $(SLASH) ;
		_in = $(_in[2-]) ;
#Echo "_RatPath got first '" $(_first) "' in = '" $(_in) "'" ;
	} else {
		if $(_in[1]) = $(DOT) && ! $(_in[2-]) {
			_first = $(_first) $(DOT) ;
			_in = $(_in[2-]) ;
#Echo "_RatPath got first '" $(_first) "' in = '" $(_in) "'" ;
		}
	}
	while $(_in) {
#Echo "Next = " $(_in[1]) " and last = " $(_rio[1]) ;
		if $(_in[1]) = $(DOT) {
			_gotdot = true ;
		}
		# if the .. will cancel out the previous directory
		if $(_in[1]) = $(DOTDOT) && $(_rio[1]) && $(_rio[1] != $(DOTDOT)  {
			_rio = $(_rio[2-]) ;		# Remove previous
#Echo "Found .. so removed previous and got _rio = " $(_rio) ;
		} else {						# Add next
			# If we're decending with a directory
			if $(_in[1]) != $(DOT) {		
				_rio = $(_in[1]) $(_rio) ;
#Echo "Adding so _rio = " $(_rio) ;
			} else {
#Echo "Found . so ignoring got _rio = " $(_rio) ;
			}
		}
		_in = $(_in[2-]) ;
	}
	# Make sure that a single dot is preserved
	if $(_gotdot) && ! $(_rio) {
		_rio = $(DOT) ;
	}
#Echo "Final _rio = " $(_rio) ;
	# Reverse it 
	for _i in $(_rio) {
		_out = $(_i) $(_out) ;
	}

	# Preprent with first */
	_out = $(_first) $(_out) ;

#Echo "_RatPath rationalized to '" $(_out) "'" ;
#Echo ;

	return $(_out) ;
}

# Re-root a directory path by pre-pending the given path.
# Don't do this if the path is absolute
# Don't return anything if the path is empty.
# p1 p2 .. file = _RootPath d1 d2 .. : p1 p2 ... file ; 
rule _RootPath
{
	local _i _out = ;

#Echo "_RootPath called with '" $(<) "' and '" $(>) "'" ;

	if ! $(>[1]) {
#Echo "_RootPath no RHS returning '" $(<) "'" ;
		return $(<) ;
	}

	if $(>[1]) = "/" || $(>[1]) = "\\" {
#Echo "_RootPath RHS = / returning '" $(<) "'" ;
		return $(>) ;
	}
	if $(NT) {
		switch $(>[1]) {
			case *:* : {
#Echo "_RootPath RHS = drive: returning '" $(<) "'" ;
				return $(>) ;
			}
		}
	}

#Echo "_RootPath returning '" $(<) $(>) "'" ;
	return $(<) $(>) ;

}

# Re-root a set of directory paths by pre-pending the given path.
# Don't do this if the path is absolute
# Don't return anything if the path is empty.
# paths = RootPaths dir : paths ; 
rule RootPaths
{
	local _d = [ _SepPath $(<[1]) ] ;
	local _i _t ;
	local _out = ;

#Echo "RootPaths got dir '" $(<[1]) "' and paths '" $(>) "'" ;
	for _i in $(>)
	{
		_t =    [ _SepPath $(_i) ] ;
		_t =    [ _RootPath $(_d) : $(_t) ] ;
		_t =    [ _RatPath $(_t) ] ;
		_out += [ _DirName $(_t) ] ;
	}

#Echo "RootPaths returns to '" $(_out) "'" ;

	return $(_out) ;
}

# - - - - - - - - - - - - - - 

# Rationalize a set of paths (ie. cancell dirs & .. )
# paths = RatPaths paths ;
rule RatPaths
{
	local _i _t ;
	local _out = ;

#Echo "RatPaths got '" $(<) "'" ;
	for _i in $(<)
	{
		_t =    [ _SepPath $(_i) ] ;
		_t =    [ _RatPath $(_t) ] ;
		_out += [ _DirName $(_t) ] ;
	}

#Echo "RatPaths returns to '" $(_out) "'" ;

	return $(_out) ;
}

# Normalize a set of paths. This resolves the
# paths location with respect to SUBDIR, and so
# accounting for the location of the Jamfile
# the path is declared, and rationalizes the result.
# If the optional dir is present, use it to
# locate their targets rather than SUBDIR.
# If paths is empty, nothing is returned.
# SRCDIR and DSTDIR are ignored.
# paths = NormPaths paths : [ dir ] ;
rule NormPaths
{
	return [ _NormPaths $(<) : $(>) : "none" ] ;
}

# Normalize a set of Source paths. This resolves the
# paths location with respect to SUBDIR, and so
# accounting for the location of the Jamfile
# the path is declared, and rationalizes the result.
# If the optional dir is present, use it to
# locate thie targets rather than SUBDIR.
# If paths is empty, nothing is returned.
# paths = NormPaths paths : [ dir ] ;
rule NormSrcPaths
{
	return [ _NormPaths $(<) : $(>) : "src" ] ;
}

# Normalize a set of destination paths. This resolves the
# paths location with respect to SUBDIR, and so
# accounting for the location of the Jamfile
# the path is declared, and rationalizes the result.
# If the optional dir is present, use it to
# locate thie targets rather than SUBDIR.
# If paths is empty, nothing is returned.
# paths = NormPaths paths : [ dir ] ;
rule NormDstPaths
{
	return [ _NormPaths $(<) : $(>) : "dst" ] ;
}

# Normalize a set of paths. This resolves the
# paths location with respect to SUBDIR, and so
# accounting for the location of the Jamfile
# the path is declared, and rationalizes the result.
# If the optional dir is present, use it to
# locate thie targets rather than SUBDIR.
# If paths is empty, nothing is returned.
# paths = NormPaths paths : dir : type ;
# (This and the other rules it calls, is probably a good candidate for speed optimization!)
#
#  ~~~~~ This isn't working correctly -
#  i.e. given "." where . = ccast and "../ccast",
#  it still returns "../ccast".
rule _NormPaths
{
	local _p _i _t ;
	local _out = ;
	local _src _dst ;

	if $(>) {
		_p = [ _SepPath $(>[1]) ] ;
		_p = [ _RatPath $(_p) ] ;
	} else {
		_p = $(_SUBDIR) ;
	}

	_src = [ _SepPath $(SRCDIR) ] ;
	_dst = [ _SepPath $(DSTDIR) ] ;

#Echo "_NormPaths got '" $(<) "' dir '" $(_p) "' type '" $(3) "'srcdir "' $(_src) "' dstdir '" $(_dst) "'" ;
	for _i in $(<)
	{
#Echo "_i = '" $(_i) "'" ; 
		_t =    [ _SepPath $(_i) ] ;
#Echo "_SepPath _i = '" $(_t) "'" ; 
		_t =    [ _RootPath $(_p) : $(_t) ] ;
#Echo "_RootPath _t = '" $(_t) "'" ; 

		if $(_src) && $(3) = "src" {
			_t = [ _RootPath $(_src) : $(_t) ] ;
#Echo "_src += _t = '" $(_i) "'" ; 

		} else if $(_dst) && $(3) = "dst" {
			local _f ;
			_t = [ _DirName $(_t) ] ;
			_f = [ _SepPath $(_t:BS) ] ;
			_t = $(_t:D) ;
			if ! $(_t) {
				_t = $(DOT) ;
			}
			_t = [ _RootPath [ _SepPath $(_t) ] : $(_dst) ] $(_f) ;
#Echo " _t += _dst = '" $(_t) "'" ; 
		}
		_t = [ _RatPath $(_t) ] ;
#Echo "_RatPath _t = '" $(_t) "'" ; 
		# Special case of complete cancelation that can occure for a pure
		# directory path (?)
		if $(_t) = "" {
			_t = "." ;
		}
		_t = [ _DirName $(_t) ] ;
		_out += $(_t) ;
#Echo "_out += '" $(_t) "'" ; 
	}

#Echo "_NormPaths returns '" $(_out) "'" ;
	return $(_out) ;
}

# Normalize a set of targets. 
# This is the same as NormPaths except it
# then strips the path out and uses it to set the
# Grist, NOMLOC, LOCATE and SEARCH on the target.
# If the optional dir is present, use it to
# locate the targets rather than SUBDIR.
# Ignore SRCDIR if present.
# paths = NormTargets paths [ : dir ] ;
rule NormISrcTargets
{
	return [ _NormTargets $(<) : $(>) : "isrc" ] ;
}

# Normalize a set of targets. 
# This is the same as NormPaths except it
# then strips the path out and uses it to set the
# Grist, NOMLOC, LOCATE and SEARCH on the target.
# If the optional dir is present, use it to
# locate the targets rather than SUBDIR.
# se DSTDIR if present.
# paths = NormTargets paths [ : dir ] ;
rule NormIDstTargets
{
	return [ _NormTargets $(<) : $(>) : "idst" ] ;
}

# Normalize a set of targets. 
# This is the same as NormPaths except it
# then strips the path out and uses it to set the
# Grist, NOMLOC, LOCATE and SEARCH on the target.
# If the optional dir is present, use it to
# locate the targets rather than SUBDIR.
# Use SRCDIR if present.
# paths = NormTargets paths [ : dir ] ;
rule NormSrcTargets
{
	return [ _NormTargets $(<) : $(>) : "src" ] ;
}

# Normalize a set of targets. 
# This is the same as NormPaths except it
# then strips the path out and uses it to set the
# Grist, NOMLOC, LOCATE and SEARCH on the target.
# If the optional dir is present, use it to
# locate the targets rather than SUBDIR.
# Use DSTDIR if present.
# paths = NormTargets paths [ : dir ] ;
rule NormDstTargets
{
	return [ _NormTargets $(<) : $(>) : "dst" ] ;
}

# Normalize a set of targets. 
# This is the same as NormPaths except it
# then strips the path out and uses it to set the
# Grist, NOMLOC, LOCATE and SEARCH on the target.
# If the optional dir is present, use it to
# locate the targets rather than SUBDIR.
# paths = NormTargets paths : dir : type ;
rule _NormTargets
{
	local _p _i _t _d _ds ;
	local _out = ;
	local _src _dst ;

	if $(>) {
		_p = [ _SepPath $(>[1]) ] ;
	} else {
		_p = $(_SUBDIR) ;
	}

	if $(3) = "src" || $(3) = "dst" {
		_src = [ _SepPath $(SRCDIR) ] ;
		_dst = [ _SepPath $(DSTDIR) ] ;
	}

#Echo ;
#Echo "_NormTargets got '" $(<) "' base = '" $(_p) "' type '" $(3) "' srcdir = '" $(_src) "' dstdirr = '" $(_dst) "'" ;
	for _i in $(<)
	{
		_t = [ _SepPath $(_i) ] ;
#Echo " _t = '" $(_t) "'" ;
		_t = [ _RootPath $(_p) : $(_t) ] ;
#Echo " _t = '" $(_t) "'" ;
		_t = [ _RatPath $(_t) ] ;
#Echo " _t = '" $(_t) "'" ;
		_t = [ _DirName $(_t) ] ;
#Echo " _t = '" $(_t) "'" ;
		_d = $(_t:D) ;
#Echo " _d = '" $(_d) "'" ;
		_ds = [ _SepPath $(_d) ] ;
#Echo " _ds = '" $(_ds) "'" ;
		_t = $(_t:D=) ;
#Echo " _t = '" $(_t) "'" ;
		_t = $(_t:G=$(_ds:J=!)) ;
#Echo " _t = '" $(_t) "'" ;

		# dst trumps all the others
		if $(3) = "dst" {
			if $($(_t)-target) != "dst" {
				NOMLOC on $(_t) = $(_d) ;
				if $(_dst) {
					if ! $(_ds) {
						_ds = $(DOT) ;
					}
					_d = [ _DirName [ _RootPath $(_ds) : $(_dst) ] ] ;
				}
				if $(_d) = "/" || $(_d) = "\\" {	# Jam has a bug when locating in root
					_d = $(_d). ;
				}
				LOCATE on $(_t) = $(_d) ;
				$(_t)-target = "dst" ;
			}

		# idst trumps src and isrc
		} else if $(3) = "idst" {
			if $($(_t)-target) != "dst" && $($(_t)-target) != "idst" {
				NOMLOC on $(_t) = $(_d) ;
				if $(_d) = "/" || $(_d) = "\\" {	# Jam has a bug when locating in root
					_d = $(_d). ;
				}
				LOCATE on $(_t) = $(_d) ;
				$(_t)-target = "idst" ;
			}

		# src trumps isrc
		} else if $(3) = "src" {
			if $($(_t)-target) != "dst" && $($(_t)-target) != "idst"
			                            && $($(_t)-target) != "src" {
				local _d1 _d2 ;
				NOMLOC on $(_t) = $(_d) ;
				if $(_src) {
					_d1 = [ _DirName [ _RootPath $(_src) : $(_ds) ] ] ;
				} else {
					_d1 = $(_d) ;
				}
				if $(_dst) {
					if ! $(_ds) {
						_ds = $(DOT) ;
					}
					_d2 = [ _DirName [ _RootPath $(_ds) : $(_dst) ] ] ;
				}
				if $(_d1) = "/" || $(_d1) = "\\" {	# Jam has a bug when locating in root
					_d1 = $(_d1). ;
				}
				if $(_d2) = "/" || $(_d2) = "\\" {	# Jam has a bug when locating in root
					_d2 = $(_d2). ;
				}
				# We assume that if we've got a DSTDIR here, then
				# it may apply to this source, even if it is never
				# gets labelled this way. - ie. it may be a dst of a
				# Jamfile with the same DSTDIR that's not in scope.
				SEARCH on $(_t) = $(_d2) $(_d1) ;
				$(_t)-target = "src" ;
			}

		# isrc is lowest priority
		} else if $(3) = "isrc" && ! $($(_t)-target) {
			if $(_d) = "/" || $(_d) = "\\" {	# Jam has a bug when locating in root
				_d = $(_d). ;
			}
			NOMLOC on $(_t) = $(_d) ;
			SEARCH on $(_t) = $(_d) ;
			$(_t)-target = "isrc" ;
		}
	
#Echo "On '" $(_t) "' set LOCATE = '" [ geton $(_t) : LOCATE ] "' SEARCH = '" [ geton $(_t) : SEARCH ] "' NOMLOC = '" [ geton $(_t) : NOMLOC ] "'" ; 
		_out += $(_t) ;
	}

#Echo "_NormTargets returns to '" $(_out) "'" ;
	return $(_out) ;
}

# Given a set of normalized paths, return the Target ID's for
# them (ie. Gristed version of path)
# IDs = _TargetIDs targpaths ;
rule _TargetIDs
{
	local _i _t _d _ds ;
	local _out = ;

#Echo "_TargetIDs got '" $(<) "'" ;
	for _i in $(<)
	{
		_d = $(_i:D) ;
		_ds = [ _SepPath $(_d) ] ;
		_t = $(_i:D=) ;
		_t = $(_t:G=$(_ds:J=!)) ;
		_out += $(_t) ;
	}

#Echo "_TargetIDs returning '" $(_out) "'" ;
	return $(_out) ;
}


# Copy the target related "on" variables from one
# target to another.
#rule CopyTarget dest : source ;
rule CopyTarget 
{
	NOMLOC on $(<) = [ geton $(>) : NOMLOC ] ;
	LOCATE on $(<) = [ geton $(>) : LOCATE ] ;
	SEARCH on $(<) = [ geton $(>) : SEARCH ] ;
}

# Make sure a non-target isn't LOCATED or SEARCH'd by
# setting LOCATE, SEARCH and NOMLOC to "" 
#rule NotTargets vars ;
rule NotTargets 
{
	NOMLOC on $(<) = "" ;
	LOCATE on $(<) = "" ;
	SEARCH on $(<) = "" ;
}

# Create a destination target by locating
# the given files in the given directory.
# The dir is assumed to be normalized.
# SRCDIR and DSTDIR are ignored.
# targs = SetTargetsLoc targs : dir ;
rule CreateIDstTargets
{
	local _o ;
#Echo "CreateIDstTargets got '" $(<) "' and '" $(>) "'" ;
	_o = [ NormIDstTargets $(<:BS) : $(>[1]) ] ;
#Echo "CreateIDstTargets returning '" $(_o) "'" ;
	return $(_o) ;
}

# Given a normalized target, return the
# orgiginal path to it. 
# (We use NOMLOC to do this.)
# path = DeNormTargs target ;
rule DeNormTargs
{
	local _i _t _p _out = ;
	
	for _i in $(<) {
		_p = [ geton $(_i) : NOMLOC ] ;
		_t = $(_i:G=) ;
		_out += $(_t:D=$(_p)) ;
	}

	return $(_out) ;
}

# Given a list of directories and a list of files,
# simply concatenate them in combination separated by a / 
# paths1/paths = CatPaths path1 : paths ;
rule CatPaths
{
	return $(<)$(SLASH)$(>) ;
}

# Try and locate a given file pattern starting from the current
# directory and working towards the root. 
# We use a heuristic to figure out when to stop, since
# Jam doesn't have pwd :-(
# found = FindRoot starting_dir : file ;
rule FindToRoot
{
	local dir = $(<[1]) ;
	local dir_list, prev_list = ;
	local dir_list;
	local found = ;

#Echo "FindToRoot got starting_dir '" $(<) "' file '" $(>) "'" ;
    found = [ GLOB $(dir) : $(>[1]) ] ;

	if $(found) {
		return $(found) ;
	}

#Echo "dir_list = " $(dir_list) ;

	dir_list = [ GLOB $(dir) : * ] ;
	while $(dir_list:D="") != $(prev_list:D="") {
		dir = $(dir)$(SLASH)$(DOTDOT) ;
#Echo "dir = " $(dir) ;
	    found = [ GLOB $(dir) : $(>[1]) ] ;

		if $(found) {
			return $(found) ;
		}

		prev_list = $(dir_list) ;
		dir_list = [ GLOB $(dir) : * ] ;
#Echo "dir_list = " $(dir_list) ;
	}
#Echo "returning " $(found) ;
	return $(found) ;
}

# -----------------------------------------

rule DoInit
{
	if ! $(DONEANCHORINIT) {
	
		SUBDIR ?= $(DOT) ;
		_SUBDIR ?= $(DOT) ;

		# initial "parent" settings
		P_ASFLAGS = ;
		P_CCFLAGS = ;
		P_C++FLAGS = ;
		P_LINKFLAGS = ;
		P_SHLINKFLAGS = ;
		P_HDRS = ;
		P_DEFINES = ;

		P_PREF_ASFLAGS = ;
		P_PREF_CCFLAGS = ;
		P_PREF_C++FLAGS = ;
		P_PREF_LINKFLAGS = ;
		P_PREF_SHLINKFLAGS = ;

		FindTop ;		# Look for a default project file 

		TRACESTDHDRS = false ;		# don't trace system path #include file dependenicies
		DONEANCHORINIT = true ;
	}
}

# Set the project top for this Jamfile and all sub Jamfiles
# until another top is set or we return.
# ProjTop d1 d2 .. ;
rule ProjTop
{
#Echo "ProjTop got '" $(<) "'" ;

	_TOP = [ _RatPath $(<) ] ;
	TOP = [ _DirName $(_TOP) ] ;

#Echo "ProjTop set TOP to '" $(TOP) "'" ;

	if ! $($(TOP)-SET) {	# Not tried to read the project file

		local found = [ GLOB $(_top) : $(JAMFILE) ] ;

		if $(found) {
			local save__SUBDIR = $(_SUBDIR) ;
			local save__INVSUBDIR = $(_INVSUBDIR) ;
			local save_SUBDIR = $(SUBDIR) ;

			_SUBDIR = $(_TOP) ;
			_INVSUBDIR = [ _InvertPath $(_SUBDIR) ] ;
			SUBDIR = [ _DirName $(_SUBDIR) ] ;
#Echo "_SUBDIR = '" $(_SUBDIR) "'" ; 
#Echo "_INVSUBDIR = '" $(_INVSUBDIR) "'" ; 

			# Translate SRCDIR for new SUBDIR
			if $(SRCDIR) {
#Echo "SRCDIR olddir '" $(SRCDIR) "'" ; 
				SRCDIR = [ _SepPath $(SRCDIR) ] ;
				SRCDIR = [ _RootPath $(_INVSUBDIR) : [ _RootPath $(SRCDIR) : $(_SUBDIR) ] ] ; 
				SRCDIR = [ _DirName [ _RatPath $(SRCDIR) ] ] ;
#Echo "SRCDIR newdir '" $(SRCDIR) "'" ; 
			}

#Echo "About to include Jamtop '" $(found) "'" ;
			include $(found) ;

			# Un Translate SRCDIR, in case it was set in the rules directory
			if $(SRCDIR) {
#Echo "_SUBDIR = '" $(_SUBDIR) "'" ; 
#Echo "_INVSUBDIR = '" $(_INVSUBDIR) "'" ; 
#Echo "SRCDIR newdir '" $(SRCDIR) "'" ; 
				SRCDIR = [ _SepPath $(SRCDIR) ] ;
				SRCDIR = [ _RootPath $(_SUBDIR) : [ _RootPath $(SRCDIR) : $(_INVSUBDIR) ] ] ; 
				SRCDIR = [ _DirName [ _RatPath $(SRCDIR) ] ] ;
#Echo "SRCDIR olddir '" $(SRCDIR) "'" ; 
			}

			# Restore things
			_SUBDIR = $(save__SUBDIR) ;
			_INVSUBDIR = $(save__INVSUBDIR) ;
			SUBDIR = $(save_SUBDIR) ;
		} else {
			Echo "WARNING :- no project " $(TOP) "Jamtop found" ;
		}
		
		$(TOP)-SET = true ;
	}
}

# Search for the project top by looking for the Jamtop
# starting at $(SUBDIR) and lookup upwards. 
# FindTop ;
rule FindTop
{
#Echo ;
#Echo "FindTop called SUBDIR = '" $(SUBDIR) "'" ;

	local _JRF = [ FindToRoot $(SUBDIR) : $(JAMTOP) ] ;

#Echo "FindTop found '" $(_JRF) "'" ;
	if $(_JRF) {

		_TOP = [ _RatPath [ _SepPath $(_JRF:D) ] ] ;
		TOP = [ _DirName $(_TOP) ] ;
#Echo "ProjTop set TOP to '" $(TOP) "'" ;

		if ! $($(TOP)-SET) {	# Not tried to read the project file
			local save__SUBDIR = $(_SUBDIR) ;
			local save__INVSUBDIR = $(_INVSUBDIR) ;
			local save_SUBDIR = $(SUBDIR) ;

			_SUBDIR = $(_TOP) ;
			_INVSUBDIR = [ _InvertPath $(_SUBDIR) ] ;
			SUBDIR = [ _DirName $(_SUBDIR) ] ;
#Echo "_SUBDIR = '" $(_SUBDIR) "'" ; 
#Echo "_INVSUBDIR = '" $(_INVSUBDIR) "'" ; 

			# Translate SRCDIR for new SUBDIR
			if $(SRCDIR) {
#Echo "SRCDIR olddir '" $(SRCDIR) "'" ; 
				SRCDIR = [ _SepPath $(SRCDIR) ] ;
				SRCDIR = [ _RootPath $(_INVSUBDIR) : [ _RootPath $(SRCDIR) : $(_SUBDIR) ] ] ; 
				SRCDIR = [ _DirName [ _RatPath $(SRCDIR) ] ] ;
#Echo "SRCDIR newdir '" $(SRCDIR) "'" ; 
			}

#Echo "About to include Jamtop '" $(_JRF) "'" ;
			include $(_JRF) ;
			$(TOP)-SET = true ;

			# Un Translate SRCDIR, in case it was set in the ruls directory
			if $(SRCDIR) {
#Echo "_SUBDIR = '" $(_SUBDIR) "'" ; 
#Echo "_INVSUBDIR = '" $(_INVSUBDIR) "'" ; 
#Echo "SRCDIR newdir '" $(SRCDIR) "'" ; 
				SRCDIR = [ _SepPath $(SRCDIR) ] ;
				SRCDIR = [ _RootPath $(_SUBDIR) : [ _RootPath $(SRCDIR) : $(_INVSUBDIR) ] ] ; 
				SRCDIR = [ _DirName [ _RatPath $(SRCDIR) ] ] ;
#Echo "SRCDIR olddir '" $(SRCDIR) "'" ; 
			}

			# Restore things
			_SUBDIR = $(save__SUBDIR) ;
			_INVSUBDIR = $(save__INVSUBDIR) ;
			SUBDIR = $(save_SUBDIR) ;
		}
	} else {
		Echo "WARNING :- no project Jamtop found, no TOP set !" ;

		if ! $(TOP) {
			TOP = $(DOT) ;		# set a default TOP 
			_TOP = $(DOT) ;
		}
	}
}

# Given a path relative to CWD, return the inverse direction
# path. Return nothing if the path is absolute.
# [ we're using a hack here, since Jam 2.5 doesn't have
#   any functions that will simply resolve a path relative
#   to CWD into an absolute path. ]
# d1 d2 .. = _InvertPath d1 d2 .. 
rule _InvertPath
{
	local _i _o _d ;
#Echo "_InvertPath got '" $(<) "'" ;
	if $(<[1]) = "/" || $(<[1]) = "\\" {
#Echo "_InvertPath returning nothing" ;
		return "" ;
	}
	if $(NT) {
		switch $(<[1]) {
			case *:* : {
#Echo "_InvertPath returning nothing" ;
				return "" ;
			}
		}
	}

	for _i in $(<) {
#Echo "_InvertPath _i = '" $(_i) "' _o = '" $(_o) "'" ;
		# Ignore .
		if $(_i) = $(DOT) {
			continue ;
		}
		# The hard one. Look amongst all the
		# sub directories for one that has the same
		# contents as the directory we came from.
		# Too bad if two directories have the same contents...
		if $(_i) = $(DOTDOT) {
			local _j;
			local _d1 _d2 _l1, _l2 _l3 ;

#Echo "_InvertPath inverting '" $(_i) "'" ;

			_d1 = [ _DirName $(_d) ] ; 
			_l1 = [ GLOB $(_d1) : * ] ;
#Echo "_d1 = '" $(_d1) "'" ;
			_d += $(_i) ;
			_d2 = [ _DirName $(_d) ] ; 
#Echo "_d2 = '" $(_d2) "'" ;
			_l2 = [ GLOB $(_d2) : * ] ;

			for _j in $(_l2) {
				if $(_j) = $(DOT) || $(_j) = $(DOTDOT) {
					continue ;
				}
#Echo "Checking _j = '" $(_j) "'" ;
				_l3 = [ GLOB $(_j) : * ] ;
#Echo "_l1 = '" $(_l1) "'" ;
#Echo "_l3 = '" $(_l3:BS) "'" ;
				if $(_l3:BS) = $(_l1) {
#Echo "Found reverse = '" $(_j) "'" ;
					_o = $(_j:BS) $(_o) ;
					break ;
				}
			}

		# The easy one. the opposite of a directory
		# is ..
		} else {
			_o = $(DOTDOT) $(_o) ;
			_d += $(_i) ;
		}
	}
	if ! $(_o) {
		_o = $(DOT) ;
	}

#Echo "_InvertPath returning '" $(_o) "'" ;
	return $(_o) ;
}

# Variables containing (possible) relative paths that are to remain
# anchored to where they were declared. This is to prevent
# NormPath in a sub-Jamfile assuming they are relative to that Jamfile.
# (This is a bit messy. How could it be avoided ? If there were
#  a simple way of making paths absolute, rather than computing eveything
#  relative to the invokation directory, it could help.)
ANCHORED_PATH_VARS = ;

# Variables to save before starting a new Jamfile, then
# restore once it's finished. 

SUBDIR_VARS = SUBDIR _SUBDIR TOP _TOP SRCDIR DSTDIR 
              P_ASFLAGS P_CCFLAGS P_C++FLAGS P_LINKFLAGS P_SHLINKFLAGS
              ASFLAGS CCFLAGS C++FLAGS LINKFLAGS SHLINKFLAGS
              P_PREF_ASFLAGS P_PREF_CCFLAGS P_PREF_C++FLAGS P_PREF_LINKFLAGS
              PREF_ASFLAGS PREF_CCFLAGS PREF_C++FLAGS PREF_LINKFLAGS PREF_SHLINKFLAGS
              P_HDRS HDRS
              P_DEFINES DEFINES
              P_LINKOBJS LINKOBJS
              P_LINKLIBS LINKLIBS
              P_LINKSHLIBS LINKSHLIBS
              P_SHLINKOBJS SHLINKOBJS
              P_SHLINKLIBS SHLINKLIBS
              P_SHLINKSHLIBS SHLINKSHLIBS
              ;

# Implement including a Jamfile from a sub or peer directory,
# Sub includes cause flags/headers/options to be inhereted
# from the calling Jamfile, while Peer includes do not.
# The global _JAMINCLUDE_PEER variable controls whether
# this is a sub or peer include.
# _JamInclude dir ;
rule _JamInclude
{
#Echo "_JamInclude called with '" $(<) "' SUBDIR '" $(SUBDIR) "' and _JAMINCLUDE_PEER '" $(_JAMINCLUDE_PEER) "'" ;

	# Save certain variables so that sub-Jamfiles don't affect them
	local _jamfile ;
	local _SUBDIR_VARS = $(SUBDIR_VARS) $(ANCHORED_PATH_VARS) ;
	local _i parent_$(_SUBDIR_VARS) ;

	for _i in $(_SUBDIR_VARS) {
		parent_$(_i) = $($(_i)) ;
	}

	if $(_JAMINCLUDE_PEER) != "true" {
		# Incorporate this levels extra flags & header paths into the base 
		P_ASFLAGS += $(ASFLAGS) ;
		P_CCFLAGS += $(CCFLAGS) ;
		P_C++FLAGS += $(C++FLAGS) ;
		P_LINKFLAGS += $(LINKFLAGS) ;
		P_SHLINKFLAGS += $(SHLINKFLAGS) ;
		P_HDRS = [ NormPaths $(HDRS) ] $(P_HDRS) ;
		P_DEFINES += $(DEFINES) ;
		P_LINKOBJS = [ NormPaths $(LINKOBJS) ] $(P_LINKOBJS) ;
		P_LINKLIBS = [ NormPaths $(LINKLIBS) ] $(P_LINKLIBS) ;
		P_LINKSHLIBS = [ NormPaths $(LINKSHLIBS) ] $(P_LINKSHLIBS) ;
		P_SHLINKOBJS = [ NormPaths $(SHLINKOBJS) ] $(P_SHLINKOBJS) ;
		P_SHLINKLIBS = [ NormPaths $(SHLINKLIBS) ] $(P_SHLINKLIBS) ;
		P_SHLINKSHLIBS = [ NormPaths $(SHLINKSHLIBS) ] $(P_SHLINKSHLIBS) ;

		# Set parent flags no existing parent flags
		if ! $(P_PREF_ASFLAGS) {
			P_PREF_ASFLAGS = $(PREF_ASFLAGS) ; }
		if ! $(P_PREF_CCFLAGS) {
			P_PREF_CCFLAGS = $(PREF_CCFLAGS) ; }
		if ! $(P_PREF_C++FLAGS) {
			P_PREF_C++FLAGS = $(PREF_C++FLAGS) ; }
		if ! $(P_PREF_LINKFLAGS) {
			P_PREF_LINKFLAGS = $(PREF_LINKFLAGS) ; }
		if ! $(P_PREF_SHLINKFLAGS) {
			P_PREF_SHLINKFLAGS = $(PREF_SHLINKFLAGS) ; }
	}
	
	# Set default for new Jamfile extra and preferred flags
	ASFLAGS = ;
	CCFLAGS = ;
	C++FLAGS = ;
	LINKFLAGS = ;
	SHLINKFLAGS = ;
	HDRS = ;
	DEFINES = ;
	LINKOBJS = ;
	LINKLIBS = ;
	LINKSHLIBS = ;
	SHLINKOBJS = ;
	SHLINKLIBS = ;
	SHLINKSHLIBS = ;

	PREF_ASFLAGS = ;
	PREF_CCFLAGS = ;
	PREF_C++FLAGS = ;
	PREF_LINKFLAGS = ;
	PREF_SHLINKFLAGS = ;

	_SUBDIR = [ _RatPath [ _RootPath $(_SUBDIR) : [ _SepPath $(<) ] ] ] ;
	_INVSUBDIR = [ _InvertPath $(_SUBDIR) ] ;
	SUBDIR = [ _DirName $(_SUBDIR) ] ;

#Echo "new _SUBDIR =" $(_SUBDIR) ;
#Echo "new _INVSUBDIR =" $(_INVSUBDIR) ;

	if $(_INVSUBDIR) != "." {
		# Keep paths relative to where they were defined, so that
		# NormPaths doesn't think they are relative to the sub-Jamfile.
#Echo "Before ANCHORED_PATH_VARS = $(ANCHORED_PATH_VARS) vals $($(ANCHORED_PATH_VARS))" ;
		for _i in $(ANCHORED_PATH_VARS) {
			$(_i) = [ RootPaths $(_INVSUBDIR) : $($(_i)) ] ;
		}
#Echo "After ANCHORED_PATH_VARS = $(ANCHORED_PATH_VARS) vals $($(ANCHORED_PATH_VARS))" ;
	}

	# Translate SRCDIR for new SUBDIR
#Echo "SRCDIR olddir '" $(SRCDIR) "'" ; 
	if $(SRCDIR) {
		local subdir = $(_SUBDIR[2-]) ;
		local invsubdir = [ FReverse $(_INVSUBDIR) ] ;
		invsubdir = [ FReverse $(invsubdir[2-]) ] ;
#Echo "subdir-1 =" $(subdir) ;
#Echo "invsubdir-1 =" $(invsubdir) ;
		SRCDIR = [ _SepPath $(SRCDIR) ] ; 
		SRCDIR = [ _RootPath $(invsubdir) : [ _RootPath $(SRCDIR) : $(subdir) ] ] ; 
		SRCDIR = [ _DirName [ _RatPath $(SRCDIR) ] ] ;
#Echo "SRCDIR newdir '" $(SRCDIR) "'" ; 
	}

	_jamfile = [ NormSrcPaths $(JAMFILE) ] ;

#Echo "About to include " $(_jamfile) ;
	include $(_jamfile) ;

	# Restore variable before returning 
	for _i in $(_SUBDIR_VARS) {
		$(_i) = $(parent_$(_i)) ;
	}

#Echo "Done include " $(JAMFILE:D=$(_subdir)) ;
#Echo "restored SUBDIR =" $(SUBDIR) ;
#Echo "_JamInclude done" ;
}

# Invoke a Jamfile as a sub Jamfile
# SubInclude dir ;
rule SubInclude
{
#Echo "### SubInclude called with '" $(<[1]) "' and SUBDIR = '" $(SUBDIR) "'" ;
	_JAMINCLUDE_PEER = "false" ;	# This is a sub include
	return [ _JamInclude $(<) ] ;
}

# Invoke a Jamfile in as a peer Jamfile
# PeerInclude dir ;
rule PeerInclude
{
#Echo "### PeerInclude called with '" $(<[1]) "' and SUBDIR = '" $(SUBDIR) "'" ;
	_JAMINCLUDE_PEER = "true" ;	# This is a peer include
	return [ _JamInclude $(<) ] ;
}

# ===========================================================
#
# Rules
#

# Public As
# As obj : source.s ;					.s -> .o
rule As
{
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<[1]:S=$(SUFOBJ)) ] ;
	local _s = [ NormSrcTargets $(>) ] ;

	Depends $(_t) : $(_s) ;
	Depends obj : $(_t) ;
	MakeLocate $(_t) ;

	HDRS on $(_t) = [ geton $(_t) : SEARCH ] [ NormPaths $(HDRS) ] $(P_HDRS) ;
}

# Internal As
rule As_
{
	local pref_asflags = $(P_PREF_ASFLAGS) ;
	pref_asflags ?= $(PREF_ASFLAGS) ;
	ASFLAGS1 on $(<) = $(P_ASFLAGS) $(ASFLAGS) ;
	ASFLAGS2 on $(<) = $(pref_asflags) ;
	ASFLAGS on $(<) = [ geton $(<) : ASFLAGS1 ] [ geton $(<) : ASFLAGS2 ] ;
	ASHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
}

# copies sources into directory.
# SRCDIR and DSTDIR will be ignored.
# Bulk directory : sources ;
rule Bulk
{
#Echo "Bulk got '" $(<) "' and '" $(>) "'" ;
	local _d = [ NormPaths $(<) ] ; # Directory
	local _s = [ NormSrcTargets $(>) ] ;	# Sources
	local _t = [ CreateIDstTargets $(_s) : $(_d) ] ; # Relocate targs to dir
	local _is _it ;			# individual source and target

	for _is in $(_s)
	{
		_it = $(_t[1]) ;
		_t = $(_t[2-]) ;	# Track _is 

		Depends files : $(_it) ;
		Depends $(_it) : $(_is) ;
		MakeLocate $(_it) ;
		File_ $(_it) : $(_is) ;
		MODE on $(_it) = $(FILEMODE) ;
		Chmod_ $(_it) ;
	}
}

# Cc object : source : flags : defines : hdrpaths ; 
rule Cc
{
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<[1]:S=$(SUFOBJ)) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;

	Depends $(_t) : $(_s) ;
	Depends obj : $(_t) ;
	Clean clean : $(_t) ;
	MakeLocate $(_t) ;

	HDRS on $(_t) = [ geton $(_t) : SEARCH ] [ NormPaths $(HDRS) ] $(P_HDRS) ;
	SOURCE on $(_t) = $(_s) ;

	HDRRULE on $(_s) = HdrRule ;
	HDRSCAN on $(_s) = $(HDRPATTERN) ;
	# Construct HDRSEARCH so that we can know where to look for headers
	local _dot = [ geton $(_>) : NOMLOC ] ;
	if ! $(_dot) { _dot = $(DOT) ; }
	HDRSEARCH1 on $(_s) = $(_dot) ;
	HDRSEARCH2 on $(_s) = [ NormPaths $(HDRS) ] $(P_HDRS) ;
	HDRSEARCH3 on $(_s) = [ NormPaths $(STDHDRS) ] ;
	HDRSEARCH on $(_s) = [ geton $(_s) : HDRSEARCH1 ] [ geton $(_s) : HDRSEARCH2 ]
	                     [ geton $(_s) : HDRSEARCH3 ] ;
#Echo "Cc set HDRSEARCH on '" $(_s) "' to '" [ geton $(_s) : HDRSEARCH ] "'" ;

	# propagate target specific-defines

	DEFINES on $(_t) = $(P_DEFINES) $(DEFINES) ;

	Cc_ $(_t) : $(_s) : $(3) ;

	if $(3) {
		ObjectCcFlags $(<) : $(3) ;
	}
	if $(4) {
		ObjectDefines $(<) : $(4) ;
	}
	if $(5) {
		ObjectHdrs $(<) : $(5) ;
	}
}

# Internal Cc
# Cc_ object : sources ;
rule Cc_
{
	# If the compiler's -o flag doesn't work, relocate the .o
	if $(RELOCATE)
	{
		CcMv $(<) : $(>) ;
	}

	local pref_ccflags = $(P_PREF_CCFLAGS) ;
	pref_ccflags ?= $(PREF_CCFLAGS) ;
	# Make sure we incorporate any CCFLAGS[12] on object into total
	CCFLAGS1 on $(<) += $(P_CCFLAGS) $(CCFLAGS) ;
	CCFLAGS2 on $(<) += $(pref_ccflags) ;
	CCFLAGS on $(<) = [ geton $(<) : CCFLAGS1 ] [ geton $(<) : CCFLAGS2 ] ;

#Echo "Cc object '" $(<) "' got CCFLAGS1 '" [ geton $(<) : CCFLAGS1 ] "' and CCFLAGS2 '" [ geton $(<) : CCFLAGS2 ] "' for total CCFLAGS '" [ geton $(<) : CCFLAGS ] "'" ;

	# Make sure the CCHDRS and CCDEFS are formatter correctly
	CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
	CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}

# C++ object : source : flags : defines : hdrpaths ; 
rule C++
{
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<[1]:S=$(SUFOBJ)) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;

	Depends $(_t) : $(_s) ;
	Depends obj : $(_t) ;
	Clean clean : $(_t) ;
	MakeLocate $(_t) ;

	HDRS on $(_t) = [ geton $(_t) : SEARCH ] [ NormPaths $(HDRS) ] $(P_HDRS) ;
	SOURCE on $(_t) = $(_s) ;

	HDRRULE on $(_s) = HdrRule ;
	HDRSCAN on $(_s) = $(HDRPATTERN) ;
	# Construct HDRSEARCH so that we can know where to look for headers
	local _dot = [ geton $(_>) : NOMLOC ] ;
	if ! $(_dot) { _dot = $(DOT) ; }
	HDRSEARCH1 on $(_s) = $(_dot) ;
	HDRSEARCH2 on $(_s) = [ NormPaths $(HDRS) ] $(P_HDRS) ;
	HDRSEARCH3 on $(_s) = [ NormPaths $(STDHDRS) ] ;
	HDRSEARCH on $(_s) = [ geton $(_s) : HDRSEARCH1 ] [ geton $(_s) : HDRSEARCH2 ]
	                     [ geton $(_s) : HDRSEARCH3 ] ;

	# propagate target specific-defines

	DEFINES on $(_t) = $(P_DEFINES) $(DEFINES) ;

	C++_ $(_t) : $(_s) ;

	if $(3) {
		ObjectC++Flags $(<) : $(3) ;
	}
	if $(4) {
		ObjectDefines $(<) : $(4) ;
	}
	if $(5) {
		ObjectHdrs $(<) : $(5) ;
	}
}

# Internal C++
# C++_ object : sources ;
rule C++_
{
	# If the compiler's -o flag doesn't work, relocate the .o
	if $(RELOCATE)
	{
		CcMv $(<) : $(>) ;
	}

	local pref_c++flags = $(P_PREF_C++FLAGS) ;
	pref_c++flags ?= $(PREF_C++FLAGS) ;
	# Make sure we incorporate any C++FLAGS[12] on object into total
	C++FLAGS1 on $(<) += $(P_C++FLAGS) $(C++FLAGS) ;
	C++FLAGS2 on $(<) += $(pref_c++flags) ;
	C++FLAGS on $(<) = [ geton $(<) : C++FLAGS1 ] [ geton $(<) : C++FLAGS2 ] ;

	# Make sure the CCHDRS and CCDEFS are formatter correctly
	CCHDRS on $(<) = [ on $(<) FIncludes $(HDRS) ] ;
	CCDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ;
}

rule Chmod_
{
#Echo "Chmod_ on '" $(<) "' with MODE = '" [ geton $(<) : MODE ] "'" ; 
	if $(CHMOD) { Chmod1 $(<) ; }
}

# Public use Depends that does normalisation of its targets
# (non-normalizing Depends is a built in)
# NDepends dest : source ;			make dependency
rule NDepends {
	local _t _s ;
	local _p = ;

#Echo "NDepends got '" $(<) "' and '" $(>) "'" ;

	# Don't anchor psuedo targets
	switch $(<)
	{
       case all : _p = true ;
       case first : _p = true ;
       case shell : _p = true ;
       case files : _p = true ;
       case lib : _p = true ;
       case exe : _p = true ;
       case obj : _p = true ;
       case dirs : _p = true ;
       case clean : _p = true ;
       case install : _p = true ;
       case uninstall : _p = true ;
	}

	# Normalize target names and set Grist LOCATE and SOURCE
	if ! $(_p) {
		_t = [ NormDstTargets $(<) ] ;
	} else {
		_t = $(<) ;
	}
	_s = [ NormSrcTargets $(>) ] ;

#Echo "Passing Depends '" $(_t) "' and '" $(_s) "'" ;

	Depends $(_t) : $(_s) ;
}

# Public use NoUpdate that does normalisation of its targets
# (non-normalizing NoUpdate is a built in)
# NNoUpdate dest ;			Make sure created, but don't update
rule NNoUpdate {
	local _t ;
	local _p = ;

#Echo "NNoUpdate got '" $(<) "'" ;

	# Don't anchor psuedo targets
	switch $(<)
	{
       case all : _p = true ;
       case first : _p = true ;
       case shell : _p = true ;
       case files : _p = true ;
       case lib : _p = true ;
       case exe : _p = true ;
       case obj : _p = true ;
       case dirs : _p = true ;
       case clean : _p = true ;
       case install : _p = true ;
       case uninstall : _p = true ;
	}

	# Normalize target names and set Grist LOCATE and SOURCE
	if ! $(_p) {
		_t = [ NormDstTargets $(<) ] ;
	} else {
		_t = $(<) ;
	}
	_s = [ NormSrcTargets $(>) ] ;

#Echo "Passing NoUpdate '" $(_t) "'" ;

	NoUpdate $(_t) ;
}

# Public use Includes that does normalisation of its targets
# (non-normalizing Includes is a built in)
# NDepends dest : source ;			make dependency
rule NIncludes {
	local _t _s ;
	local _p = ;

#Echo "NIncludes got '" $(<) "' and '" $(>) "'" ;

	# Normalize target names and set Grist LOCATE and SOURCE
	_t = [ NormDstTargets $(<) ] ;
	_s = [ NormSrcTargets $(>) ] ;

#Echo "Passing Includes '" $(_t) "' and '" $(_s) "'" ;

	Includes $(_t) : $(_s) ;
}

# sets mode of file
# Mod target : mode ;
rule Mod
{
	local _t = [ NormIDstTargets $(<[1]) ] ;
	MODE on $(_t) = $(>) ;
	Chmod_ $(_t) ;
}

# copies source onto target.
# SRCDIR and DSTDIR will be ignored.
# File target : source ;
rule File
{
	local _t = [ NormIDstTargets $(<[1]) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;

	Depends files : $(_t) ;
	Depends $(_t) : $(_s) ;
	Clean clean : $(_t) ;
	MakeLocate $(_t) ;
	File_ $(_t) : $(_s) ;
	MODE on $(_t) = $(FILEMODE) ;
	Chmod_ $(_t) ;
}

# copies source onto target, but doesn't clean source.
# SRCDIR and DSTDIR will be ignored.
# File target : source ;
rule FileNoClean
{
	local _t = [ NormIDstTargets $(<[1]) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;

	Depends files : $(_t) ;
	Depends $(_t) : $(_s) ;
	MakeLocate $(_t) ;
	File_ $(_t) : $(_s) ;
	MODE on $(_t) = $(FILEMODE) ;
	Chmod_ $(_t) ;
}

# Fake file copy. Creates a dependence to work around
# problem that Jam doesn't understand two products from one action.
# FakeFile target : source ;
rule FakeFile
{
	local _t = [ NormIDstTargets $(<[1]) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;

	FakeFile_ $(_t) : $(_s) ;
}

rule FakeFile_
{
	local _t = $(<) ;
	local _s = $(>) ;

	Depends files : $(_t) ;
	Depends $(_t) : $(_s) ;
	Clean clean : $(_t) ;
	MakeLocate $(_t) ;
}


# Compile Fortran source file into object
# Fortran object : source ; 
rule Fortran
{
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<[1]:S=$(SUFOBJ)) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;

	Depends $(_t) : $(_s) ;
	Depends obj : $(_t) ;
	Clean clean : $(_t) ;
	MakeLocate $(_t) ;

	Fortran_ $(_t) : $(_s) ;
}

# Internal Fortran
rule Fortran_
{
}


# NOTE! Perhaps GenFileND and GenFileNND could be replaced by a GenFile
# with a $(3) for the dependecies ?

# All > are assumed to be files that < is dependent on
# with >[1] being an executable
# SRCDIR and DSTDIR are ignored.
rule GenFile 
{
#Echo "GenFile got '" $(<) "' and '" $(>) "'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormIDstTargets $(<) ] ;
	local _s = [ NormISrcTargets $(>[1]:S=$(SUFEXE)) ] ;
	local _a = [ NormISrcTargets $(>[2-]) ] ;

#Echo "GenFile normed '" $(_t) "' and '" $(_s) "' plus '" $(_a) "'" ;
 
	Depends $(_t) : $(_s) $(_a) ;
	if ! $(_s[1]:G) {		# In case PATH doesn't have . in it.
		_s = $(DOT)$(SLASH)$(_s[1]:G=) $(_s[2-]) ;
		NotTargets $(_s) ;
		NoCare $(_s) ;
		NotFile $(_s) ;
	}
	GenFile1 $(_t) : $(_s) $(_a) ;
	Clean clean : $(_t) ;
}

rule GenFile1
{
	MakeLocate $(<) ;
}

# Only >[1] is assumed to be an executable that < is dependent on.
# $(3) are optional extra dependecies
# SRCDIR and DSTDIR are ignored.
rule GenFileND 
{
#Echo "GenFileND got '$(<)' and '$(>)' and src targets '$(_d)'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormIDstTargets $(<[1]) ] ;
	local _s = [ NormISrcTargets $(>[1]:S=$(SUFEXE)) ] ;
	local _a = $(>[2-]) ;
	_a = $(_a:J=" ") ;
	local _d = [ NormSrcTargets $(3) ] ;

#Echo "GenFileND normed '$(_t)' and '$(_s)' plus '$(_a)' and src targets '$(_d)'" ;

	NotTargets $(_a) ;
	NoCare $(_a) ;
	NotFile $(_a) ;			# Supresses "independent target", but may mark a directory wrongly
	Depends $(_t) : $(_s) $(_d) ;
#Echo "GenFileND set Depends '$(_t)' and '$(_s)' and '$(_d)'" ;

	if ! $(_s[1]:G) {		# In case PATH doesn't have . in it.
		_s = $(DOT)$(SLASH)$(_s[1]) $(_s[2-]) ;
		NotTargets $(_s) ;
		NoCare $(_s) ;
		NotFile $(_s) ;
	}
	GenFileND1 $(_t) : $(_s) $(_a) ;

	Clean clean : $(_t) ;
}

rule GenFileND1
{
	MakeLocate $(<) ;
}

# GenFileNND target : program args : extra_dependecies ;
# None of > is assumed to be a file.
# $(3) are optional extra dependecies
# SRCDIR and DSTDIR are ignored.
rule GenFileNND 
{
#Echo "GenFileNND got '$(<)' and '$(>)' and src targets '$(3)' " ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormIDstTargets $(<) ] ;
	local _a = $(>) ;
	_a = $(_a:J=" ") ;		# Split up by space delimeter ?
	local _d = [ NormSrcTargets $(3) ] ;

#Echo "GenFileNND normed '$(_t)' plus '$(_a)' and src targets '$(_d)'" ;

	Depends files : $(_t) ;
	Depends $(_t) : $(_d) ;

	NotTargets $(_a) ;
	NoCare $(_a) ;
	NotFile $(_a) ;			# Supresses "independent target", but may mark a directory wrongly
	
	GenFileNND1 $(_t) : $(_a) ;
	Clean clean : $(_t) ;
}

rule GenFileNND1
{
#Echo "GenFileNND1 got "' $(<) "' and "' $(>) "'" ;
	MakeLocate $(<) ;
}

# GenFileNNDnc target : program args : extra_dependecies ;
# Same as GenFileNND but don't clean the target.
# None of > is assumed to be a file.
# $(3) are optional extra dependecies
# SRCDIR and DSTDIR are ignored.
rule GenFileNNDnc 
{
#Echo "GenFileNNDnc got '$(<)' and '$(>)' and src targets '$(3)' " ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormIDstTargets $(<) ] ;
	local _a = $(>) ;
	_a = $(_a:J=" ") ;		# Split up by space delimeter ?
	local _d = [ NormSrcTargets $(3) ] ;

#Echo "GenFileNNDnc normed '$(_t)' plus '$(_a)' and src targets '$(_d)'" ;

	Depends files : $(_t) ;
	Depends $(_t) : $(_d) ;

	NotTargets $(_a) ;
	NoCare $(_a) ;
	NotFile $(_a) ;			# Supresses "independent target", but may mark a directory wrongly
	
	GenFileNND1 $(_t) : $(_a) ;
}

# Concatenate all the argument to the file 
# Each argument to a separate line
# If no arguments, create empty file
# SRCDIR and DSTDIR are ignored.
rule CatToFile 
{
#Echo "CatToFile got '" $(<) "' and '" $(>) "'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormIDstTargets $(<) ] ;

	MakeLocate $(_t) ;
	Depends files : $(_t) ;
	NotFile $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9) ;

	Clean clean : $(_t) ;

	if ! $(>) {
		CreateCatFile_ $(_t) ;

	} else {
		if $(2) {
			CatToFile_ $(_t) : $(2) ;
		}
		if $(3) {
			CatToFile_ $(_t) : $(3) ;
		}
		if $(4) {
			CatToFile_ $(_t) : $(4) ;
		}
		if $(5) {
			CatToFile_ $(_t) : $(5) ;
		}
		if $(6) {
			CatToFile_ $(_t) : $(6) ;
		}
		if $(7) {
			CatToFile_ $(_t) : $(7) ;
		}
		if $(8) {
			CatToFile_ $(_t) : $(8) ;
		}
		if $(9) {
			CatToFile_ $(_t) : $(9) ;
		}
	}
}

rule HardLink
{
	local _t = [ NormDstTargets $(<) ] ;
	local _s = [ NormSrcTargets $(>) ] ;

	Depends files : $(_t) ;
	Depends $(_t) : $(_s) ;

	HardLink_ $(_t) : $(_s) ;
}

# Mark executable as GUI applications (ie. OS X Bundle)
# GuiImages images ;
rule GuiBin
{
	local _t = [ NormDstTargets $(<:S=$(SUFEXE)) ] ;
	GUIAPP on $(_t) = "true" ;
}

rule GUIAPP
{
}

# /HdrMacroFile
#
# this rule is specific to FT-Jam. It is used to indicate that a given file
# contains definitions for filename macros (e.g. "#define MYFILE_H <myfile>.h")
# that can later be used in #include statements in the rest of the source
#
# these files must be parsed before any make is tried.
#
rule HdrMacroFile
{
  HDRMACRO $(<) ;
}

# Handle #includes that are found.
# Try and locate them to asociate them with declared targets, as
# well as tracing any further #includes they may have.
# HdrRule NormedSource : headers ;
rule HdrRule
{
	# N.B.		This rule is called during binding, potentially after
	# the fate of many targets has been determined, and must be
	# used with caution: don't add dependencies to unrelated
	# targets, and don't set variables on $(<).

#Echo "HdrRule got '" $(<) "' and '" $(>) "'" ;

	local _d = [ geton $(<) : NOMLOC ] ;		# Directory location of source file
	local _schpath = [ geton $(<) : HDRSEARCH ] ;	# Search path used to find these
	local _s _ts ;				# include source targets, sources to trace

#Echo "HDRSEARCH on '" $(<) "' is = '" $(_schpath) "'" ; 

	# See if we can locate the header amongst the generated files.
#Echo "Checking for matches of known targets" ;
	local _i _j _k _ss _sp _n ;
	local _stdhdrs = [ NormPaths $(STDHDRS) ] ;
	_st = ;
	for _j in $(>) {
		_sp = ;			# Search path
		_ss = ;			# Resolved source target
#Echo "Checking include '" $(_j) "'" ;
		for _k in $(_schpath)  "__unknown__" {		# search path and plain
			_n = [ NormPaths $(_j) : $(_k) ] ;		# Normalized path for that search path
			_i = [ _TargetIDs $(_n) ] ;				# Target ID/name if it exitsts
#Echo "Checking target ID '" $(_i)-target "' value '" $($(_i)-target) "'" ;
			if $($(_i)-target) {				# Target exists
				_ss = $(_i) ;
				_s += $(_ss) ;
#Echo "Found existing target '" $(_ss) "'" ;
				break ;
			} else if ! $($(_i)-target) {				# unknown state
#Echo "Unknown statis target '" $(_i) "'" ;
				_sp += [ NormPaths $(_j:D) : $(_k) ] ;	# paths to search
			}
		}
		if ! $(_ss) && $(_sp) {		# We've not seen that target 
			local _found = ;
#Echo "Searching for '" $(_j) "' in paths '" $(_sp) "'" ;
			# See if we can find the header
			_found = [ GLOB $(_sp) : $(_j:BS) ] ;

			# Hmm. This sort of works around Windows problem of std include files being upper case.
			# It won't solve the problem of tracing them if TRACESTDHDRS is true though.
			if $(NT) && ! $(_found) {
				_found = [ GLOB $(_sp) : $(_j:UBS) ] ;
				_found = $(_found:D)\\$(_found:LBS) ;
			}
			if $(_found) {
				_ss = [ NormSrcTargets $(_found[1]) ] ;		# Add it to our list
#Echo "Using new found target '" $(_ss) "'" ;
				_s += $(_ss) ;
			}
			# Mark off not found targets
			for _k in $(_schpath) {
				_n = [ NormPaths $(_j) : $(_k) ] ;	# Normalized path for that search path
				_i = [ _TargetIDs $(_n) ] ;			# Target ID/name if it exitsts
				if $(_i) = $(_ss) {
					break ;							# The one we found
				}
#Echo "marking off '" $(_i) "' as non-existant" ;
				$(_i)-target = "false" ;			# That combination doesn't exist
			}
			if ! $(_found) {
				_k = "__unknown__" ;
				_ss = [ NormSrcTargets $(_j) : $(_k) ] ;
				# ~~99 This would make good warning information ?
#Echo "Include unresolved: '" $(_ss) "'" ;
				_s += $(_ss) ;	# Use plain header name as target ID
			}
		}
		# We're left with $(_ss_) being the target and $(_k) being the search path 

		# Add this to our list that will also be scanned for #includes
#Echo "Dealt with'" $(_j) "', _ss = '" $(_ss) "' and _k = '" $(_k) "'" ;
		if  ( ! $(_k) in "__unknown__" )
		 && ( $(TRACESTDHDRS) = true || ! $(_k) in $(_stdhdrs) )  {
			_st += $(_ss) ;
		} 
	}

#Echo "Normalized includes = '" $(_s) "'" ;
#Echo "Includes to be traced = '" $(_st) "'" ;

	# Propagate on $(<) to $(>)
	# Compute header search path for any #includes in these #includes

	if $(_st)  {
		HDRSEARCH2 on $(_st) = [ geton $(<) : HDRSEARCH2 ] ;
		HDRSEARCH3 on $(_st) = [ geton $(<) : HDRSEARCH3 ] ;
		for _i in $(_st) {
			# Replace file dot/HDRSEARCH1 with one for this file
			local _dot = [ geton $(_i) : NOMLOC ] ;
			if ! $(_dot) { _dot = $(DOT) ; }
			HDRSEARCH1 on $(_i) = $(_dot) ;
			HDRSEARCH on $(_i) = [ geton $(_i) : HDRSEARCH1 ] [ geton $(_i) : HDRSEARCH2 ]
			                     [ geton $(_i) : HDRSEARCH3 ] ;
		}
		HDRSCAN on $(_st)   = [ geton $(<) : HDRSCAN ] ;
		HDRRULE on $(_st)   = [ geton $(<) : HDRRULE ] ;
		HDRGRIST on $(_st)  = [ geton $(<) : HDRGRIST ] ;
#Echo "HdrRule SEARCH on '" $(_st) "' set to '" [ geton $(_st) : SEARCH ] "'" ;
#Echo "HdrRule HDRSEARCH on '" $(_st) "' set to '" [ geton $(_st) : HDRSEARCH ] "'" ;
#Echo "HdrRule HDRSCAN on '" $(_st) "' set to '" [ geton $(_st) : HDRSCAN ] "'" ;
#Echo "HdrRule HDRRULE on '" $(_st) "' set to '" [ geton $(_st) : HDRRULE ] "'" ;
	}

	# Tell Jam that anything depending on $(<) also depends on $(>),
	# set SEARCH so Jam can find the headers, but then say we don't
	# care if we can't actually find the headers (they may have been
	# within ifdefs),

	NoCare $(_s) ;
	SEARCH on $(_s) = $(_schpath) ;		# Use search path used to find these #includes as Jam SEARCH path.
	Includes $(<) : $(_s) ;
}

# Public InstallInto 
# InstallInto dir : sources ;		install any files
rule InstallInto
{
#Echo "InstallInto got '" $(<) "' and '" $(>) "'" ;
	local _d = [ NormPaths $(<) ] ; # Directory
	local _s = [ NormSrcTargets $(>) ] ;	# Sources
	local _t = [ CreateIDstTargets $(_s) : $(_d) ] ; # Relocate targs to dir
	_InstallInto $(_t) : $(_s) ;
}

# Private InstallInto
# Note that the install rules ignore SRDDIR and DSTDIR.
# InstallInto destinations : sources ;		install any files
rule _InstallInto
{
#Echo "_InstallInto got '" $(<) "' and '" $(>) "'" ;

	local _t = $(<) ;		# targets
	local _s = $(>) ;		# sources
	local _is _it ;			# individual source and target

	# Arrange for jam install
	# Arrange for jam uninstall
	# targets are in dir

	Depends install : $(_t) ;
	Clean uninstall : $(_t) ;
	MakeLocate $(_t) ;				# create directories

	# For each source, Install, Chmod, Chown, and Chgrp

	for _is in $(_s)
	{
		_it = $(_t[1]) ;
		_t = $(_t[2-]) ;	# Track _is 

#Echo "_InstallInto installing target '" $(_it) "' from src '" $(_is) "'" ;
		Depends $(_it) : $(_is) ;
		Install $(_it) : $(_is) ;
		Chmod_ $(_it) ;

		if $(OWNER) && $(CHOWN) 
		{ 
			Chown_ $(_it) ;
			OWNER on $(_it) = $(OWNER) ;
		}

		if $(GROUP) && $(CHGRP) 
		{ 
			Chgrp_ $(_it) ;
			GROUP on $(_it) = $(GROUP) ;
		}
	}
}

# InstallBin dir : sources ;		install binaries
rule InstallBin
{
#Echo "InstallBin got '" $(<) "' and '" $(>) "'" ;
	local _d = [ NormPaths $(<) ] ; # Directory
	local _s = [ NormSrcTargets $(>:S=$(SUFEXE)) ] ;	# Sources
	local _t = [ CreateIDstTargets $(_s) : $(_d) ] ; # Relocate targs to dir
#Echo "InstallBin norm '" $(_d) "' and '" $(_s) "' and '" $(_t) "'" ;
	MODE on $(_t) = $(EXEMODE) ;
	_InstallInto $(_t) : $(_s) ;
#Echo "InstallBin done " ;
}

# InstallFile dir : sources ;		install files
rule InstallFile
{
#Echo "InstallFile got '" $(<) "' and '" $(>) "'" ;
	local _d = [ NormPaths $(<) ] ; # Directory
	local _s = [ NormSrcTargets $(>) ] ;	# Sources
	local _t = [ CreateIDstTargets $(_s) : $(_d) ] ; # Relocate targs to dir
#Echo "InstallFile normed targ '" $(_t) "' src '" $(_s) "' and dir '" $(_d) "'" ;
	MODE on $(_t) = $(FILEMODE) ;
	_InstallInto $(_t) : $(_s) ;
}

# InstallLib dir : sources ;		install static library files
rule InstallLib
{
#Echo "InstallLib got '" $(<) "' and '" $(>) "'" ;
	local _d = [ NormPaths $(<) ] ; # Directory
	local _s = [ NormSrcTargets $(>:S=$(SUFLIB)) ] ;	# Sources
	local _t = [ CreateIDstTargets $(_s) : $(_d) ] ; # Relocate targs to dir
	MODE on $(_t) = $(FILEMODE) ;
	_InstallInto $(_t) : $(_s) ;
}

# InstallShLib dir : sources ;		install shared library files
rule InstallShLib
{
#Echo "InstallShLib got '" $(<) "' and '" $(>) "'" ;
	local _d = [ NormPaths $(<) ] ; # Directory
	local _s = [ NormSrcTargets $(>:S=$(SUFSHLIB)) ] ;	# Sources
	local _t = [ CreateIDstTargets $(_s) : $(_d) ] ; # Relocate targs to dir
	MODE on $(_t) = $(FILEMODE) ;
	_InstallInto $(_t) : $(_s) ;
}

# InstallShell dir : sources ;		install files
rule InstallShell
{
#Echo "InstallShell got '" $(<) "' and '" $(>) "'" ;
	local _d = [ NormPaths $(<) ] ; # Directory
	local _s = [ NormSrcTargets $(>) ] ;	# Sources
	local _t = [ CreateIDstTargets $(_s) : $(_d) ] ; # Relocate targs to dir
	MODE on $(_t) = $(SHELLMODE) ;
	_InstallInto $(_t) : $(_s) ;
}

# InstallMan dir : sources ;		install files
rule InstallMan
{
#Echo "InstallMan got '" $(<) "' and '" $(>) "'" ;
	local _d = [ NormPaths $(<) ] ;	# Directory
	local _s = [ NormSrcTargets $(>) ] ;	# Sources
	local _t = [ CreateIDstTargets $(_s) : $(_d) ] ; # Relocate targs to dir

	# Really this just strips the . from the suffix

	local _is _it _tt _s _id ;

	_tt = $(_t) ;
	for _is in $(_s)
	{
		_it = $(_tt[1]) ;
		_tt = $(_tt[2-]) ;

		switch $(_is:S)
		{
			case .1 : s = 1 ; case .2 : s = 2 ; case .3 : s = 3 ;
			case .4 : s = 4 ; case .5 : s = 5 ; case .6 : s = 6 ;
			case .7 : s = 7 ; case .8 : s = 8 ; case .l : s = l ;
			case .n : s = n ; case .man : s = 1 ;
		}

		_id = [ RootPaths $(_d) : man$(_s) ] ;
		CreateIDstTargets $(_it) : $(_id) ;
		MODE on $(_it) = $(FILEMODE) ;
		_InstallInto $(_it) : $(_is) ;
	}
}

# Lex 
# Lex source.c : source.l ;
rule Lex
{
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<[1]) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;

	Depends $(_t) : $(_s) ;
	Clean clean : $(_t) ;
	MakeLocate $(_t) ;

	Lex_ $(_t) : $(_s) ;
}

# Internal Lex
rule Lex_
{
	LexMv_ $(<) : $(>) ;
}

# Library - create a static library from sources.
# Library library : sources : flags : defines : hdrpaths : objects ; 
rule Library
{
	LibraryFromObjects $(<) : $(>) $(6) ;
	Objects $(>) : $(3) : $(4) : $(5) ;
}

# LibraryFromObjects - create a static library from object files.
# LibraryFromObjects library : objects ;
rule LibraryFromObjects
{
	local _i ;

#Echo "LibraryFromObjects got " $(<) "and" $(>) "'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _l = [ NormDstTargets $(<[1]:S=$(SUFLIB)) ] ;
	local _s = [ NormSrcTargets $(>:S=$(SUFOBJ)) ] ;
#Echo "LibraryFromObjects nomed = " $(_l) "and" $(_s) ;

	Depends lib : $(_l) ;

	MakeLocate $(_l) ;

	if $(NOARSCAN) 
	{ 
		# If we can't scan the library to timestamp its contents,
		# we have to just make the library depend directly on the
		# on-disk object files.  

		Depends $(_l) : $(_s) ;
	}
	else
	{
		# If we can scan the library, we make the library depend
		# on its members and each member depend on the on-disk
		# object file.

		for _i in $(_s)
		{
			local _m ;
			_m = $(_l:M=$(_i:BS)) ;
			CopyTarget $(_m) : $(_l) ;	# Transfer LOCATE, SEARCH, NOMLOC
			Depends $(_l) : $(_m) ;
			Depends $(_m) : $(_i) ;
		}
	}

	Clean clean : $(_l) ;

	if $(CRELIB) {
		CreLib $(_l) : $(_s[1]) ;
	}

	Archive $(_l) : $(_s) ;

	if $(RANLIB) {
		Ranlib $(_l) ;
	}

	# If we can't scan the library, we have to leave the .o's around.
	if ! ( $(NOARSCAN) || $(NOARUPDATE) ) {
		local _ds ;
		for _i in $(_s) {
			# Don't delete any objects that we've marked with KEEPOBJS
			if ! [ geton $(_i) : KEEPOBJS ] {
				_ds += $(_i) ;
			}
		}
		if $(_ds) {
			RmTemps_ $(_l) : $(_ds) ;
		}
	}
}

# LibraryFromLibraries - create a static library from object files and static libraries.
# LibraryFromLibraries library : libraries ;
rule LibraryFromLibraries
{
	local _i ;

#Echo "LibraryFromLibraries got " $(<) "and" $(>) ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _l = [ NormDstTargets $(<[1]:S=$(SUFLIB)) ] ;
	local _s = [ NormSrcTargets $(>:S=$(SUFLIB)) ] ;
#Echo "LibraryFromObjects nomed = " $(_l) "and" $(_s) ;

	Depends lib : $(_l) ;
	Depends $(_l) : $(_s) ;

	MakeLocate $(_l) ;

	Clean clean : $(_l) ;

	if $(CRELIB) {
		CreLib $(_l) : $(_s[1]) ;
	}

	ArchiveArchive $(_l) : $(_s) ;
}

# ShLibrary - create a shared library from sources.
# ShLibrary library : sources : flags : defines : hdrpaths : objects : libs : shlibs ; 
rule ShLibrary
{
	ShLibraryFromObjects $(<) : $(>) $(6) : $(7) : $(8) ;
	Objects $(>) : $(CCSHOBJFLAG) $(3) : $(4) : $(5) ;
}

# ShLibraryFromObjects - create a shared library from object files.
# Both the import (if used on the system) and shared library will be created.
# ShLibraryFromObjects shlib : objects : libs : shlibs ;
rule ShLibraryFromObjects
{
	local _i _l ;

#Echo "ShLibraryFromObjects got " $(<) "and" $(>) ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _sl = [ NormDstTargets $(<[1]:S=$(SUFSHLIB)) ] ;
	if $(NT) {
		_l = [ NormDstTargets $(<[1]:S=$(SUFIMPLIB)) ] ;
	}
	local _s = [ NormSrcTargets $(>:S=$(SUFOBJ)) ] ;
#Echo "ShLibraryFromObjects nomed =" $(_sl) "and" $(_l) "and" $(_s) ;

	Depends lib : $(_sl) ;
#	Depends lib : $(_l) ;
	MakeLocate $(_sl) ;

	Depends $(_sl) : $(_s) ;
	Clean clean : $(_sl) $(_l) ;

	if $(_l) {
		Depends $(_l) : $(_s) ;
		Clean clean : $(_l:S=.exp) ;
	}

#Echo "ShLibraryFromObjects SHLINKFLAGS = '" $(SHLINKFLAGS) "' and P_SHLINKFLAGS ='" $(P_LSHINKFLAGS) "'" ;

	if $(SHLINKFLAGS) || $(P_SHLINKFLAGS)
	 || $(PREF_SHLINKFLAGS) || $(P_PREF_SHLINKFLAGS) {
		local pref_shlinkflags = $(P_PREF_SHLINKFLAGS) ;
		pref_shlinkflags ?= $(PREF_SHLINKFLAGS) ;
		SHLINKFLAGS on $(_sl) += $(P_SHLINKFLAGS) $(SHLINKFLAGS) $(pref_shlinkflags) ;
	}

#Echo "ShLibraryFromObjects SHLINKOBJS = '" $(SHLINKOBJS) "' and P_SHLINKOBJS ='" $(P_SHLINKOBJS) "'" ;
	if $(SHLINKOBJS) || $(P_SHLINKOBJS) {
		local _o = [ NormSrcTargets $(SHLINKOBJS:S=$(SUFOBJ)) ] $(P_SHLINKOBJS:S=$(SUFOBJ)) ;
		Depends $(_sl) : $(_o) ;
		SHLINKOBJS on $(_sl) += $(_o) ;
	}

#Echo "ShLibraryFromObjects SHLINKLIBS = '" $(SHLINKLIBS) "' and P_SHLINKLIBS ='" $(P_SHLINKLIBS) "'" ;
	if $(SHLINKLIBS) || $(P_SHLINKLIBS) {
		local _l = [ NormSrcTargets $(SHLINKLIBS:S=$(SUFLIB)) ] $(P_SHLINKLIBS:S=$(SUFLIB)) ;
		Depends $(_sl) : $(_l) ;
		SHLINKLIBS on $(_sl) += $(_l) ;
	}

#Echo "ShLibraryFromObjects SHLINKSHLIBS = '" $(SHLINKSHLIBS) "' and P_SHLINKSHLIBS ='" $(P_SHLINKSHLIBS) "'" ;
	if $(SHLINKSHLIBS) || $(P_SHLINKSHLIBS) {
		local _l = [ NormSrcTargets $(SHLINKSHLIBS:S=$(SUFSHLIB)) ] $(P_SHLINKSHLIBS:S=$(SUFSHLIB)) ;
		Depends $(_sl) : $(_l) ;
		SHLINKSHLIBS on $(_sl) += $(_l) ;
	}

	if $(SHLINKDEFFILE) {	# Windows special option
		SHLINKDEFFILE on $(_sl) $(_l) = [ NormSrcTargets $(SHLINKDEFFILE) ] ;
		Depends $(_sl) : [ geton $(_sl) : SHLINKDEFFILE ] ;
		FakeFile_ $(_l) : $(_sl) ;		# .lib is created with .dll
		ShLinkDef_ $(_sl) $(_l) : $(_s) ;
	} else {
		if (SHLINKSEARCHEXEPATH) {		# UNIX special option
	
			if $(OS) = MACOSX {		# OS X version of ld
				SHLINKSEARCHEXEPATH = @executable_path/ ;
			} else {
#				SHLINKSEARCHEXEPATH = \\$PATH/ ;
				SHLINKSEARCHEXEPATH = \\$ORIGIN/ ;
			}
		}
		ShLink_ $(_sl) $(_l) : $(_s) ;
	}

	# Try and make sure the objects are build with the correct flag
	ObjectCcFlags $(>) : $(CCSHOBJFLAG) ;
	ObjectC++Flags $(>) : $(CCSHOBJFLAG) ;

	if $(3) {
		ShLibraryLibraries $(<) : $(3) ;	
	}
	if $(4) {
		ShLibraryShLibraries $(<) : $(4) ;	
	}
}

# Internal link
rule Link_
{
	MODE on $(<) = $(EXEMODE) ;
	Chmod_ $(<) ;
}

# Make the shared library link with the given objects.
# This is just a way of adding common object files to many shlibs.
# ShLibraryObjects shlib : objects ;
rule ShLibraryObjects
{
#Echo "ShLibraryObjects got '" $(<) "' and '" $(>) "'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<:S=$(SUFSHLIB)) ] ;
	local _o = [ NormSrcTargets $(>:S=$(SUFOBJ)) ] ;

	Depends $(_t) : $(_o) ;

	SHLINKOBJS on $(_t) += $(_o) ;
}

# Make the executables link with the given static libraries.
# ShLibraryLibraries shlib : libraries ;
rule ShLibraryLibraries
{
#Echo "ShLibraryLibraries got '" $(<) "' and '" $(>) "'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<:S=$(SUFSHLIB)) ] ;
	local _l = [ NormSrcTargets $(>:S=$(SUFLIB)) ] ;

	Depends $(_t) : $(_l) ;

	SHLINKLIBS on $(_t) += $(_l) ;
}

# Make the executables link with the given shared libraries.
# ShLibraryShLibraries shlib : shlibraries ;
rule ShLibraryShLibraries
{
#Echo "ShLibraryShLibraries got '" $(<) "' and '" $(>) "'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<:S=$(SUFSHLIB)) ] ;
	local _l = [ NormSrcTargets $(>:S=$(SUFSHIMPLIB)) ] ;

	Depends $(_t) : $(_l) ;

	SHLINKSHLIBS on $(_t) += $(_l) ;
}

# Add extra LINKFLAGS to mains
# MainLinkFlags mains : flags ;
rule MainLinkFlags
{
#Echo "MainLinkFlags got '" $(<) "' and '" $(>) "'" ;
	local _t = [ NormDstTargets $(<:S=$(SUFEXE)) ] ;
	local _i ;

	for _i in $(_t) {
		LINKFLAGS on $(_i) += $(>) ;
#Echo "exes '" $(_i) "' got LINKFLAGS '" [ geton $(_i) : LINKFLAGS ] "'" ;
	}
}

# Make an executable from sources
# Main image : sources : flags : defines : hdrpaths : objects : libs : shlibs ; 
rule Main
{
	MainFromObjects $(<) : $(>) $(6) : $(7) : $(8) ;
	Objects $(>) : $(3) : $(4) : $(5) ;
}

# Make a variant executable from sources
# Objects are distiguished by appending "_image" 
# MainVariant image : sources : flags : defines : hdrpaths : objects : libs : shlibs ; 
rule MainVariant
{
	local _i _t _o ;

#Echo "MainVariant got '" $(<) "' and '" $(>) "'" ;
	for _i in $(>) {
		_t = $(_i:DB)_$(<[1]) ;
		Object $(_t) : $(_i) : $(3) : $(4) : $(5) ;
#Echo "MainVariant object '" $(_t) "' and src '" $(_i) "'" ;
		_o += $(_t) ;
	}
#Echo "MainVariant image '" $(<) "' and objs '" $(_o) "'" ;
	MainFromObjects $(<) : $(_o) $(6) : $(7) : $(8) ;
}

# Make an executable from objects
# MainFromObjects image : objects : libs : shlibs ;
rule MainFromObjects
{
#Echo "MainFromObjects got" $(<) "and" $(>) ;

	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<[1]:S=$(SUFEXE)) ] ;
	local _s = [ NormSrcTargets $(>:S=$(SUFOBJ)) ] ;

#Echo "MainFromObjects _t" $(_t) "and _s" $(_s) ;

	# so 'jam foo' works when it's really foo.exe
	if $(_t:S=) != $(_t)
	{
		Depends $(_t:S=) : $(_t) ;
		NotFile $(_t:S=) ;
	}

	# make compiled sources a dependency of target

	Depends exe : $(_t) ;
	Depends $(_t) : $(_s) ;
	Clean clean : $(_t) ;
	MakeLocate $(_t) ;

	if $(3) {
		LinkLibraries $(<) : $(3) ;	
	}
	if $(4) {
		LinkShLibraries $(<) : $(4) ;	
	}

#Echo "MainFromObjects LINKFLAGS = '" $(LINKFLAGS) "' and P_LINKFLAGS ='" $(P_LINKFLAGS) "'" ;
#Echo "                PREF_LINKFLAGS = '" $(PREF_LINKFLAGS) "' and P_PREF_LINKFLAGS ='" $(P_PREF_LINKFLAGS) "'" ;
	if $(LINKFLAGS) || $(P_LINKFLAGS)
	 || $(PREF_LINKFLAGS) || $(P_PREF_LINKFLAGS) {
		local pref_linkflags = $(P_PREF_LINKFLAGS) ;
		pref_linkflags ?= $(PREF_LINKFLAGS) ;
		LINKFLAGS on $(_t) += $(P_LINKFLAGS) $(LINKFLAGS) $(pref_linkflags) ;
#Echo "LINKFLAGS on $(_t) = '" [ geton $(_t) : LINKFLAGS ] "'" ; 
	}

#Echo "MainFromObjects LINKOBJS = '" $(LINKOBJS) "' and P_LINKOBJS ='" $(P_LINKOBJS) "'" ;
	if $(LINKOBJS) || $(P_LINKOBJS) {
		local _o = [ NormSrcTargets $(LINKOBJS:S=$(SUFOBJ)) ] $(P_LINKOBJS:S=$(SUFOBJ)) ;
		Depends $(_t) : $(_o) ;
		LINKOBJS on $(_t) += $(_o) ;
	}

#Echo "MainFromObjects LINKLIBS = '" $(LINKLIBS) "' and P_LINKLIBS ='" $(P_LINKLIBS) "'" ;
	if $(LINKLIBS) || $(P_LINKLIBS) {
		local _l = [ NormSrcTargets $(LINKLIBS:S=$(SUFLIB)) ] $(P_LINKLIBS:S=$(SUFLIB)) ;
		Depends $(_t) : $(_l) ;
		LINKLIBS on $(_t) += $(_l) ;
	}

#Echo "MainFromObjects LINKSHLIBS = '" $(LINKSHLIBS) "' and P_LINKSHLIBS ='" $(P_LINKSHLIBS) "'" ;
	if $(LINKSHLIBS) || $(P_LINKSHLIBS) {
		local _l = [ NormSrcTargets $(LINKSHLIBS:S=$(SUFIMPLIB)) ] $(P_LINKSHLIBS:S=$(SUFIMPLIB)) ;
		Depends $(_t) : $(_l) ;
		LINKSHLIBS on $(_t) += $(_l) ;
	}

	Link_ $(_t) : $(_s) ;

	# Some OS's need to post process GUI apps to work (ie. OS X bundle)
	if [ geton $(_t) : GUIAPP ] = "true" {
		GUIAPP $(_t) ;
	}
#Echo "MainFromObjects done" ;
}

# A rule to make several mains from each of their single source files.
# MainsFromSources executables ;
rule MainsFromSources
{
	local _i ;
	for _i in $(<) {
		Main $(_i) : $(_i) ;
	}
}

# Make the executables link with the given objects.
# This is just a way of adding common object files to many mains.
# LinkObjects image : objects ;
rule LinkObjects
{
#Echo "LinkObjects got '" $(<) "' and '" $(>) "'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<:S=$(SUFEXE)) ] ;
	local _o = [ NormSrcTargets $(>:S=$(SUFOBJ)) ] ;

	Depends $(_t) : $(_o) ;

	LINKOBJS on $(_t) += $(_o) ;
}

# Make the executables link with the given static libraries.
# LinkLibraries image : libraries ;
rule LinkLibraries
{
#Echo "LinkLibraries got '" $(<) "' and '" $(>) "'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<:S=$(SUFEXE)) ] ;
	local _l = [ NormSrcTargets $(>:S=$(SUFLIB)) ] ;

	Depends $(_t) : $(_l) ;

	LINKLIBS on $(_t) += $(_l) ;
}

# Make the executables link with the given shared libraries.
# LinkShLibraries image : shlibraries ;
rule LinkShLibraries
{
#Echo "LinkShLibraries got '" $(<) "' and '" $(>) "'" ;
	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<:S=$(SUFEXE)) ] ;
	local _l = [ NormSrcTargets $(>:S=$(SUFSHIMPLIB)) ] ;

	Depends $(_t) : $(_l) ;

	LINKSHLIBS on $(_t) += $(_l) ;
}

# Ensure that each targets directories are created
# Makelocate targets ;
rule MakeLocate
{
#Echo "MakeLocate got '" $(<) "'" ;
	local _i ;
	# Uses special variable LOCATE of targets, and arranges
	# with MkDir to create target directory.
	# The directory itself becomes a target

	for _i in $(<) {
		local _t = [ geton $(_i) : LOCATE ] ;
		if $(_t) {
			MkDir_ $(_t) : $(_i) ;
		}
	}
}

# Make the directories and all their parent directories.
# MkDir directories ;
rule MkDir
{
#Echo "MkDir got '" $(<) "'" ;
	# Ignore timestamps on directories: we only care if they exist.
	local _t= [ NormPaths $(<) ] ;
	local _i ;

	for _i in $(_t) {
		MkDir_ $(_i) ;
	}
}

# Internal MkDir
# MkDir dir [ : dependency ] 
rule MkDir_
{
#Echo "MkDir_ got '" $(<) "' : '" $(>) "'" ;

	if ! $(<:BS) {
		return ;
	}

	local _t ;
	local _d = $(<:D) ;			# Form target id from path + last directory
	if ! $(_d) {
		_d = $(DOT) ;
	}
	local _t = [ NormIDstTargets $(<:BS) : $(_d) ] ;

#Echo "MkDir_ target = '" $(_t) "' dependant = '" $(>) "'" ;

	if $(>) {		# Thing that depends on this directory 
		Depends $(>) : $(_t) ;
	}
	NoUpdate $(_t) ;

	# Don't create . or any directory already created.

	if $(_t) != $(DOT) && ! $($(_t)-mkdir) 
	{
		# Cheesy gate to prevent multiple invocations on same dir
		# Arrange for jam dirs
		# MkDir1 has the actions 

#Echo "Making '" $(_t) "'" ;
		$(_t)-mkdir = true ;
		Depends dirs : $(_t) ;
		MkDir1 $(_t) ;

		# Recursively make parent directories.
		# $(_t:P) = $(_t)'s parent, & we recurse until root

		local _s = $(<:P) ;
#Echo "parent = '" $(_s) "'" ;

		# Don't try to create A: or A:\ on windows

		if $(NT)
		{
			switch $(_s)
			{
				case *:   : _s = ;
				case *:\\ : _s = ;
				case *:/  : _s = ;
			}
		}

#Echo "parent now = '" $(_s) "'" ;
		if $(_s) = $(SLASH)		# Hmm. Was $(_s) = $(<). How could that work ?
		{
#Echo "At root, ignore '" $(_s) "' = '" $(<) "'" ;
			# The parent is the same as the dir.
			# We're at the root, which some OS's can't stat, so we mark
			# it as NotFile.

			NotFile $(_s) ;
		}
		else if $(_s)  
		{
			# There's a parent; recurse.

#Echo "Doing Depends '" $(_t) "' with '" [ _TargetIDs $(_s) ] "'" ;
			Depends $(_t) : [ _TargetIDs $(_s) ] ;
#Echo "Recursing with parent '" $(_s) "'" ;
			MkDir_ $(_s) ;
		}
	} else {
#Echo "Not making '" $(_t) "' because it's dot, or it's been made before" ;
	}
}

# Deal with a single source to object.
# Object object : sources : flags : defines : hdrpaths 
rule Object
{
	#Echo "Object got " $(<) "and" $(>) "' flags '" $(3) "' defs '" $(4) "' hds '" $(5) "'" ;

	# Normalize target names and set Grist LOCATE and SOURCE
	local _t = [ NormDstTargets $(<[1]:S=$(SUFOBJ)) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;
	local _dot ;

#Echo "Object norms " $(_t) "and" $(_s) ;

	Depends $(_t) : $(_s) ;
	Depends obj : $(_t) ;
	Clean clean : $(_t) ;
	MakeLocate $(_t) ;

	#  HDRS is used to provide the -I$(HDRS) options on compile.

#Echo "Object sets HDRS on '" $(_t) "' to HDRS '" $(HDRS) "' and P_HDRS '" $(P_HDRS) "'" ;
	HDRS on $(_t) = [ geton $(_t) : SEARCH ] [ NormPaths $(HDRS) ] $(P_HDRS) ;
#Echo "HDRS on '" $(_t) "' is now '" [ geton $(_t) : HDRS ] "'" ;

	# we need to mark what the associated source is so
	# that if we want to change HDRS we can propogate
	# it to the  #include files.

	SOURCE on $(_t) = $(_s) ;		# ~~99 should check source is the same as any previous ?

	# handle #includes for source: Jam scans for headers with
	# the regexp pattern $(HDRSCAN) and then invokes $(HDRRULE)
	# with the scanned file as the target and the found headers
	# as the sources.  HDRSEARCH is the value of SEARCH used for
	# the found header files. 

	HDRRULE on $(_s) = HdrRule ;
	HDRSCAN on $(_s) = $(HDRPATTERN) ;

	# Construct HDRSEARCH so that we can latter add to HDRS
	local _dot = [ geton $(_s) : NOMLOC ] ;
	if ! $(_dot) { _dot = $(DOT) ; }
	HDRSEARCH1 on $(_s) = $(_dot) ;
	HDRSEARCH2 on $(_s) = [ NormPaths $(HDRS) ] $(P_HDRS) ;
	HDRSEARCH3 on $(_s) = [ NormPaths $(STDHDRS) ] ;
	HDRSEARCH on $(_s) = [ geton $(_s) : HDRSEARCH1 ] [ geton $(_s) : HDRSEARCH2 ]
	                     [ geton $(_s) : HDRSEARCH3 ] ;
#Echo "Object: HDRSEARCH on '" $(_s) "' set to '" [ geton $(_s) : HDRSEARCH ] "'" ;

	# propagate target specific-defines

	DEFINES on $(_t) = $(P_DEFINES) $(DEFINES) ;

	# if source is not .c, generate .c with specific rule

	switch $(_s:S)
	{
		case .asm : As_ $(_t) : $(_s) ;

		case .c :	Cc_ $(_t) : $(_s) ;

		case .C :	C++_ $(_t) : $(_s) ;
		case .cc :	C++_ $(_t) : $(_s) ;
		case .cpp : C++_ $(_t) : $(_s) ;
		case .cxx : C++_ $(_t) : $(_s) ;

		case .m :	Cc_ $(_t) : $(_s) ;

		case .f :	Fortran_ $(_t) : $(_s) ;

		case .l :	{
						local _c = $(_t:S=.c) ;
						CopyTarget $(_c) : $(_t) ;	# Transfer LOCATE, SEARCH, NOMLOC
						Lex_ $(_c) : $(_s) ;
						Cc_ $(_t) : $(_c) ;
					}

		case .s :	As_ $(_t) : $(_s) ;

		case .y :	{
						local _c = $(_t:S=$(YACCGEN)) ;
						CopyTarget $(_c) : $(_t) ;	# Transfer LOCATE, SEARCH, NOMLOC
						Yacc_ $(_c) : $(_s) ;
						Cc_ $(_t) : $(_c) ;
					}
		# Note user object gets normalized target and source
		case * :	UserObject $(_t) : $(_s) : $(3) : $(4) : $(5) ;
	}
#Echo ;

	if $(3) {
		ObjectCcFlags $(<) : $(3) ;
		switch $(_s:S)
		{
			case .c :	ObjectCcFlags $(_t) : $(3) ;

			case .C :	ObjectC++Flags $(_t) : $(3) ;
			case .cc :	ObjectC++Flags $(_t) : $(3) ;
			case .cpp : ObjectC++Flags $(_t) : $(3) ;
			case .cxx : ObjectC++Flags $(_t) : $(3) ;

			case .l :	ObjectCcFlags $(_t) : $(3) ;
			case .y :	ObjectCcFlags $(_t) : $(3) ;
		}
	}
	if $(4) {
		ObjectDefines $(<) : $(4) ;
	}
	if $(5) {
		ObjectHdrs $(<) : $(5) ;
	}
}

# Add extra CCFLAGS to objects
# ObjectCcFlags objects : flags ;
rule ObjectCcFlags
{
#Echo "ObjectCcFLags got '" $(<) "' and '" $(>) "'" ;
	local _t = [ NormDstTargets $(<:S=$(SUFOBJ)) ] ;
	local _i ;

	for _i in $(_t) {
		CCFLAGS1 on $(_i) += $(>) ;
		CCFLAGS on $(_i) = [ geton $(_i) : CCFLAGS1 ] [ geton $(_i) : CCFLAGS2 ] ;
#Echo "object '" $(_i) "' got CCFLAGS1 '" [ geton $(_i) : CCFLAGS1 ] "' and CCFLAGS2 '" [ geton $(_i) : CCFLAGS2 ] "' for total CCFLAGS '" [ geton $(_i) : CCFLAGS ] "'" ;
	}
}

# Add extra PREF_CCFLAGS to objects
# ObjectPrefCcFlags objects : flags ;
rule ObjectPrefCcFlags
{
#Echo "ObjectPrefCcFLags got '" $(<) "' and '" $(>) "'" ;
	if ! $(P_PREF_CCFLAGS) {
		local _t = [ NormDstTargets $(<:S=$(SUFOBJ)) ] ;
		local _i ;

		for _i in $(_t) {
			CCFLAGS2 on $(_i) += $(>) ;
			CCFLAGS on $(_i) = [ geton $(_i) : CCFLAGS1 ] [ geton $(_i) : CCFLAGS2 ] ;
#Echo "object '" $(_i) "' got CCFLAGS1 '" [ geton $(_i) : CCFLAGS1 ] "' and CCFLAGS2 '" [ geton $(_i) : CCFLAGS2 ] "' for total CCFLAGS '" [ geton $(_i) : CCFLAGS ] "'" ;
		}
	}
}

# Add extra C++FLAGS to objects
# ObjectC++Flags objects : flags ;
rule ObjectC++Flags
{
#Echo "ObjectC++FLags got '" $(<) "' and '" $(>) "'" ;
	local _t = [ NormDstTargets $(<:S=$(SUFOBJ)) ] ;
	local _i ;

	for _i in $(_t) {
		C++FLAGS1 on $(_i) += $(>) ;
		C++FLAGS on $(_i) = [ geton $(_i) : C++FLAGS1 ] [ geton $(_i) : C++FLAGS2 ] ;
	}
}

# Add extra PREF_C++FLAGS to objects
# ObjectPrefC++Flags objects : flags ;
rule ObjectPrefC++Flags
{
#Echo "ObjectPrefC++FLags got '" $(<) "' and '" $(>) "'" ;
	if ! $(P_PREF_C++FLAGS) {
		local _t = [ NormDstTargets $(<:S=$(SUFOBJ)) ] ;
		local _i ;

		for _i in $(_t) {
			C++FLAGS2 on $(_i) += $(>) ;
			C++FLAGS on $(_i) = [ geton $(_i) : C++FLAGS1 ] [ geton $(_i) : C++FLAGS2 ] ;
		}
	}
}

# Add extra DEFINES to objects
# ObjectDefines objects : defines ;
rule ObjectDefines
{
	# must reformat CCDEFS according to current defines

	local s = [ NormDstTargets $(<:S=$(SUFOBJ)) ] ;

	DEFINES on $(s) += $(>) ;
	CCDEFS on $(s) = [ on $(s) FDefines $(DEFINES) ] ;
}

# Add extra header search paths to objects.
# ObjectHdrs objects : dirs ;
rule ObjectHdrs
{
#Echo "ObjectHdrs HDRS got '" $(<) "' and '" $(>) "'" ;
	# Add to HDRS for CCHDRS benefit.
	local _t = [ NormDstTargets $(<:S=$(SUFOBJ)) ] ;
	local _h = [ NormSrcPaths $(>) ] ;
	local _i _s ;

#Echo "ObjectHdrs changed  HDRS on '" $(_t) "' from '" [ geton $(_t) : HDRS ] "'" ;
	HDRS on $(_t) += $(_h) ;
#Echo " to '" [ geton $(_t) : HDRS ] "'" ;
	for _i in $(_t) {
		_s = [ geton $(_i) : SOURCE ] ;
#Echo " obj '" $(_i) "' has source '" $(_s) "'" ;
#Echo " ObjectHdrs changed HDRSEARCH on '" $(_s) "' from '" [ geton $(_s) : HDRSEARCH ] "'" ;
		HDRSEARCH2 on $(_s) += $(_h) ;
		HDRSEARCH on $(_s) = [ geton $(_s) : HDRSEARCH1 ] [ geton $(_s) : HDRSEARCH2 ]
		                     [ geton $(_s) : HDRSEARCH3 ] ;
#Echo "  to '" [ geton $(_s) : HDRSEARCH ] "'" ;
		CCHDRS on $(_i) = [ on $(_i) FIncludes $(HDRS) ] ;
	}
}

# Set KEEPOBJS on the given headers
# ObjectKeep objects ;
rule ObjectKeep
{
#Echo "ObjectKeep got '" $(<) "" ;
	local _t = [ NormDstTargets $(<:S=$(SUFOBJ)) ] ;

	KEEPOBJS on $(_t) = "true" ;
#Echo "ObjectHdrs changed  KEEPOBJS on '" $(_t) "' to '" [ geton $(_t[1]) : KEEPOBJS ] "'" ;
}

# Create object files from sources.
# Objects sources : flags : defines : hdrpaths ; 
rule Objects
{
#Echo "Objects got src '" $(<) "' flags '" $(2) "' def '" $(3) "' hdrs '" $(4) "'" ;
	local _i ;

	for _i in $(<) {
		Object $(_i) : $(_i) : $(2) : $(3) : $(4) ;
	}
}

# Marks sources as temporary with the TEMPORARY rule, and deletes sources once targets  are built.
# Must be the last rule invoked on targets. 
# RmTemps targets : sources ;
rule RmTemps
{
	local _s = [ NormPaths $(>) ] ;
	if $(_s) {
		RmTemps_ $(<) : $(_s) ;
	}
}

# internal RmTemps
rule RmTemps_
{
	Temporary $(>) ;
}

# Setuid
rule Setuid
{
	local _t = [ NormPaths $(>:S=$(SUFEXE)) ] ;
	MODE on $(_t) = 4755 ;
}

# Shell
rule Shell
{
	local _t = [ NormTargs $(>:S=$(SUFSH)) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;
	Shell_ $(_t) : $(_s) ;
}

# internal Shell
rule Shell_
{
	Depends shell : $(<) ;
	Depends $(<) : $(>) ;
	MODE on $(<) = $(SHELLMODE) ;
	Clean clean : $(<) ;
	Chmod_ $(<) ;
}

# SoftLink
rule SoftLink
{
	local _t = [ NormDstTargets $(<) ] ;
	local _s = [ NormSrcTargets $(>) ] ;

	SoftLink_ $(_t) : $(_s) ;
}

# internal SoftLink
rule SoftLink_
{
	Depends files : $(<) ;
	Depends $(<) : $(>) ;
	Clean clean : $(<) ;
}

#Adds flags to mark symbols as undefined on link command for images
rule Undefines
{
	local _t = [ NormDstTargets $(<) ] ;
	UNDEFS on [ $(_t:S=$(SUFEXE)) ] += $(UNDEFFLAG)$(>) ;
}

# User routine to handle objects. Note that
# targets and sources are in normalized form.
rule UserObject
{
	Exit "Unknown suffix on" $(>) "- see UserObject rule in Jamfile(5)." ;
}

# Yacc source.c : source.y ;
rule Yacc
{
	local _t = [ NormDstTargets $(<[1]) ] ;
	local _s = [ NormSrcTargets $(>[1]) ] ;

	Yacc_ $(_t) : $(_s) ;
}

# internal Yacc
rule Yacc_
{
	local _h ;

	_h = $(<:S=.h) ;
	CopyTarget $(_h) : $(<) ;	# Transfer LOCATE, SEARCH, NOMLOC

	# Some places don't have a yacc.

	MakeLocate $(<) $(_h) ;

	if $(YACC)
	{
		Depends $(<) : $(>) ;
		FakeFile_ $(_h) : $(<) ;		# .h is created with .c
		Yacc1_ $(<) $(_h) : $(>) ;
		YaccMv_ $(<) $(_h) ;
		Clean clean : $(<) $(_h) ;
	}

	# make sure someone includes $(_h) else it will be
	# a deadly independent target

	Includes $(<) : $(_h) ;
}

# Aswig : source.i ;
# Argyll C class generator. Creates C class declaration source.h,
# C class partial implementation source_i.c, C++ class wrapper
# declaration & implementation source.hpp.
rule Aswig
{
#Echo "Aswig called with $(>) " ;
	local _s = [ NormSrcTargets $(>[1]) ] ;

	Aswig_ : $(_s) ;
}

# internal Aswig
rule Aswig_
{
#Echo "Aswig_ called with $(>)" ;
	local _i = $(>[1]) ;
	local _h = $(_i:S=.h) ;
	CopyTarget $(_h) : $(_i) ;		# Transfer LOCATE, SEARCH, NOMLOC
	local _c = $(_i:B=$(_i:B)_i:S=.c) ;
	CopyTarget $(_c) : $(_i) ;		# Transfer LOCATE, SEARCH, NOMLOC
	local _hpp = $(_i:S=.hpp) ;
	CopyTarget $(_hpp) : $(_i) ;	# Transfer LOCATE, SEARCH, NOMLOC

#Echo "Aswig_ creates $(_h) $(_c) $(_hpp) from $(_i) " ;

	MakeLocate $(_h) $(_c) $(_hpp) ;

	Depends $(_h) : $(_i) ;
	FakeFile_ $(_c) : $(_h) ;		# _i.c is created with .h
	FakeFile_ $(_hpp) : $(_h) ;		# _.hpp is created with .h
	Aswig1_ $(_h) : $(_i) ;
	Clean clean : $(_h) $(_c) $(_hpp) ;
}

#
# Utility rules; no side effects on these
#

# FReverse a1 a2 a3 ... ;
# return ... a3 a2 a1 ;
rule FReverse 
{

	local _i _o = ;
	for _i in $(1)
	{
		_o = $(_i) $(_o) ;
	}
	return $(_o) ;
}

# Strip common initial elements of variables v1 and v2.
# Modifies the variable values themselves.
# FStripCommon v1 : v2 ;
rule FStripCommon
{

	if $($(<)[1]) && $($(<)[1]) = $($(>)[1])
	{
		$(<) = $($(<)[2-]) ;
		$(>) = $($(>)[2-]) ;
		FStripCommon $(<) : $(>) ;
	}
}

# Append suffix if there is not already one
# E.g., "FAppendSuffix yacc lex foo.bat : $(SUFEXE) ;"
# returns (yacc,lex,foo.bat) on Unix and 
# (yacc.exe,lex.exe,foo.bat) on NT.
# FAppendSuffix files : suffix ;
rule FAppendSuffix
{

	if $(>)
	{
		local _i _o ;

		for _i in $(<)
		{
			if $(_i:S)
			{
				_o += $(_i) ;
			}
			else
			{
				_o += $(_i:S=$(>)) ;
			}
		}
		return $(_o) ;
	}
	else
	{
		return $(<) ;
	}
}

# return a1 a2 ... with any empty elements deleted
# FDelEmpty a1 a2 ... ;
rule FDelEmpty 
{

	local _i _o = ;
	for _i in $(<)
	{
		if $(_i) {
			_o += $(_i) ;
		}
	}
	return $(_o) ;
}

#
# Operating system specific utility rules
# First, the (generic) UNIX versions
#

rule FQuote { return \\\"$(<)\\\" ; }
rule FDefines { local _t = [ FDelEmpty $(<) ] ; return -D$(_t) ; }
rule FIncludes { local _t = [ FDelEmpty $(<) ] ; return -I$(_t) ; }

if $(OS2)
{
	rule FQuote { return \"$(<)\" ; }
	rule FIncludes { local _t = [ FDelEmpty $(<) ] ; return /I$(_t) ; }
}

else if $(NT)
{
	if ! $(MINGW) {
		rule FDefines { local _t = [ FDelEmpty $(<) ] ; return /D$(_t) ; }
		rule FIncludes { local _t = [ FDelEmpty $(<) ] ; return /I$(_t) ; }
	}
}

else if $(MAC)
{
	rule FQuote { return \"$(<)\" ; }
	rule FDefines { local _t = [ FDelEmpty $(<) ] ; return "-define '$(_t)'" ; }
	rule FIncludes { local _t = [ FDelEmpty $(<) ] ; return \"$(_t:J=,)\" ; }
}

else if $(VMS)
{
	rule FQuote { return \"\"\"$(<)\"\"\" ; }
	rule FDefines { local _t = [ FDelEmpty $(<) ] ; return "/define=( $(_t:J=,) )" ; }
	rule FIncludes { local _t = [ FDelEmpty $(<) ] ; return "/inc=( $(_t:J=,) )" ; }

	rule FDirName
	{
			local _s _i ;

			# Turn individual elements in $(<) into a usable path.

			if ! $(<)
			{
				_s = $(DOT) ;
			}
			else 
			{
				# This handles the following cases:
				#		 a -> [.a]
				#		 a b c -> [.a.b.c]
				#		 x: -> x:
				#		 x: a -> x:[a]
				#		 x:[a] b -> x:[a.b]

				switch $(<[1])
				{
					case *:* : _s = $(<[1]) ;
					case \\[*\\] : _s = $(<[1]) ;
					case * : _s = [.$(<[1])] ;
				}

				for _i in [.$(<[2-])]
				{
					_s = $(_i:R=$(_s)) ;
				}
			}

			return $(_s) ;
	}
}

#
# Actions
#

#
# First the defaults
#

actions updated together piecemeal Archive
{
	$(AR) $(<) $(>)
}

actions together ArchiveArchive
{
	mkdir .jamArchiveArchive$PPID
	cp $(>) .jamArchiveArchive$PPID 
	cd .jamArchiveArchive$PPID 
	for i in $(>:BS)
	do
    	ar -xo $i
	done
    cd ..
	ar -r $(<) .jamArchiveArchive$PPID/*.o
	rm -rf .jamArchiveArchive$PPID
}

actions As
{
	$(AS) $(ASFLAGS) $(ASHDRS) -o $(<) $(>)
}

actions C++_
{
	$(C++) -c -o $(<) $(C++FLAGS) $(CCDEFS) $(CCHDRS) $(>)
}

actions Cc_
{
	$(CC) -c -o $(<) $(CCFLAGS) $(CCDEFS) $(CCHDRS) $(>)
}

actions Chgrp_
{
	$(CHGRP) $(GROUP) $(<)
}

actions Chmod1
{
	$(CHMOD) $(MODE) $(<)
}

actions Chown_
{
	$(CHOWN) $(OWNER) $(<)
}

actions piecemeal together existing Clean
{
	$(RM) $(>)
}

actions File_
{
	$(CP) $(>) $(<)
}

#actions FakeFile_ { }

actions GenFile1
{
	$(>[1]) $(<) $(>[2-])
}

actions GenFileND1
{
	$(>)
}

actions GenFileNND1
{
	$(>)
}

actions CreateCatFile_ 
{
	$(CP) /Y nul $(<) > nul
}

actions CatToFile_
{
	echo $(>) >> $(<)
}

actions Fortran_
{
	$(FORTRAN) $(FORTRANFLAGS) -o $(<) $(>)
}

actions HardLink_
{
	$(RM) $(<) && $(LN) $(>) $(<)
}

actions Install
{
	$(CP) $(>) $(<) 
}

actions Lex_
{
	$(LEX) $(>)
}

actions LexMv_
{
	$(MV) lex.yy.c $(<)
}

#	Old: $(LINK) $(LINKFLAGS) $(LINKOUTFLAG)$(<) $(UNDEFS) $(>) $(LINKOBJS) $(LINKLIBS) $(LINKSHLIBS) $(STDLIBS) 
#	$(LINK) $(LINKOUTFLAG)$(<) $(UNDEFS) $(>) $(LINKFLAGS) $(LINKOBJS) $(LINKLIBS) $(LINKSHLIBS) $(STDLIBS) 
actions Link_ bind LINKOBJS LINKLIBS LINKSHLIBS
{
	$(LINK) $(LINKOUTFLAG)$(<) $(UNDEFS) $(>) $(LINKOBJS) $(LINKLIBS) $(LINKSHLIBS) $(LINKFLAGS) $(STDLIBS)  
}

if $(OS) = MACOSX {		# OS X version of ld

	# Link .o and .a into a .dylib
	# gcc -dynamiclib -Wl,-headerpad_max_install_names,-undefined,dynamic_lookup,-compatibility_version,1.0,-current_version,1.0,-install_name,/usr/local/lib/libfoo.1.dylib -o libfoo.1.dylib $(OBJ)
	# -Wl,-install_name,@executable_path ???
	actions ShLink_ bind SHLINKOBJS SHLINKLIBS SHLINKSHLIBS  
	{
		$(LINK) -dynamiclib -Wl,-undefined,dynamic_lookup,-install_name,$(SHLINKSEARCHEXEPATH)$(<[1]:BS) $(LINKOUTFLAG)$(<[1]) $(>) $(SHLINKOBJS) $(SHLINKLIBS) $(SHLINKSHLIBS) $(SHLINKFLAGS) $(SHSTDLIBS)
	}

} else {	# General gcc

	# Link .o and .a into a .so
	# To set .so search path: -Wl,-rpath,$(LINKSHLIBS:D) 
	# or set LD_LIBRARY_PATH
	# or set /etc/ld.so.conf.d/*.conf
	# To set .so search path (after flag):  -Wl,-soname=$(<[1]:BS)
# Old:	$(LINK) -shared -Wl,-soname=$(SHLINKSEARCHEXEPATH)$(<[1]:BS) $(SHLINKFLAGS) $(LINKOUTFLAG)$(<[1]) $(>) $(SHLINKOBJS) $(SHLINKLIBS) $(SHLINKSHLIBS) $(SHSTDLIBS)
	actions ShLink_ bind SHLINKOBJS SHLINKLIBS SHLINKSHLIBS  
	{
		$(LINK) -shared -Wl,-soname=$(SHLINKSEARCHEXEPATH)$(<[1]:BS) $(LINKOUTFLAG)$(<[1]) $(>) $(SHLINKOBJS) $(SHLINKLIBS) $(SHLINKSHLIBS) $(SHLINKFLAGS) $(SHSTDLIBS)
	}
}

actions MkDir1
{
	$(MKDIR) $(<)
}

actions together Ranlib
{
	$(RANLIB) $(<)
}

actions quietly updated piecemeal together RmTemps_
{
	$(RM) $(>)
}

actions Shell_
{
	$(AWK) '
		NR == 1 { print "$(SHELLHEADER)" }
		NR == 1 && /^[#:]/ { next }
		/^##/ { next }
		{ print }
	' < $(>) > $(<)
}

actions SoftLink_
{
	$(RM) $(<) && $(LN) -s $(>) $(<)
}

actions Yacc1_
{
	$(YACC) $(YACCFLAGS) $(>)
}

actions YaccMv_ 
{
	$(MV) $(YACCFILES).c $(<[1])
	$(MV) $(YACCFILES).h $(<[2])
}

actions Aswig1_
{
	aswig $(ASWIGFLAGS) -c++ -a2c $(>)
}

#
# RELOCATE - for compilers with broken -o flags
#

if $(RELOCATE)
{
	actions C++_
	{
		$(C++) -c $(C++FLAGS) $(CCDEFS) $(CCHDRS) $(>)
	}

	actions Cc_
	{
		$(CC) -c $(CCFLAGS) $(CCDEFS) $(CCHDRS) $(>)
	}

	actions ignore CcMv
	{
		[ $(<) != $(>:BS=$(SUFOBJ)) ] && $(MV) $(>:BS=$(SUFOBJ)) $(<)
	}
}

#
# NOARUPDATE - can't update an archive
#

if $(NOARUPDATE)
{
	actions Archive
	{
		$(AR) $(<) $(>)
	}
}

#
# UNIX specific actions
#

if $(UNIX)
{
	actions GenFile1
	{
		PATH="$PATH:."
		$(>[1]) $(<) $(>[2-])
	}

	actions CreateCatFile_ 
	{
		$(CP) /dev/null $(<) 
	}

	actions CatToFile_
	{
		echo "$(>)" >> $(<)
	}

	# Make OS X GUI apps work
	if $(OS) = MACOSX
	{

		# Used to use /Developer/Tools/Rez -t APPL Carbon.r -o $(<)
		# but this no longer works in OS X 10.5, and we don't need this
		# stuff with TransformProcessType()
		# Another alternative is to use link option "-sectcreate __TEXT __info_plist Info.plist" ???
		# to embed the plist in the executable, but not sure what should be in plist.
		# Pure GUI app
		actions GUIAPP
		{
			rm -rf $(<).app
			mkdir -p $(<).app
			mkdir $(<).app/Contents
			mkdir $(<).app/Contents/Resources
			mkdir $(<).app/Contents/MacOS
			echo APPLnone > $(<).app/Contents/PkgInfo
			mv $(<) $(<).app/Contents/MacOS
			chmod 755 $(<).app/Contents/MacOS/$(<:BS)
			cat << EOF > $(<).app/Contents/info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
        <key>CFBundleName</key>
        <string>$(<:BS)</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleVersion</key>
        <string>59</string>
        <key>CFBundleShortVersionString</key>
        <string>1.1</string>
        <key>CFBundleSignature</key>
        <string>none</string>
</dict>
</plist>
EOF
			cat << EOF > $(<)
#!/bin/sh
\$0.app/Contents/MacOS/$(<:BS)
EOF
			chmod 755 $(<)
		}
	}
}

#
# NT specific actions
#

if $(NT) 
{
	# Ensure timestamp is updated

	actions File_
	{
		$(CP) /b $(>) + nul $(<) > nul
	}

	actions Install
	{
		$(CP) /b $(>) + nul $(<) > nul
	}
}

if $(NT) && $(MSVCNT)
{
#	actions updated together piecemeal Archive
#	{
#		if exist $(<) set _$(<:B)_=$(<)
#		$(AR) /out:$(<) %_$(<:B)_% $(>)
#	}

	# This is slightly dodgy if you've got multiple
	# libraries with the same name in different directories with
	# jam -j n, or you have .obj's distinguished only by their directory
	# being combined into the same library, but it overcomes
	# the problem of lib not updating a library properly if
	# jam is involked from different directories.
	actions updated together piecemeal Archive
	{
		if exist $(<:BS)_ RMDIR /S/Q $(<:BS)_
		MKDIR $(<:BS)_
		for %%i in ( $(>) ) do COPY %%i $(<:BS)_ 1>nul
		if exist $(<) set _$(<:B)_=$(<)
		$(AR) /out:$(<) %_$(<:B)_% $(<:BS)_\*
		DEL /F/S/Q $(<:BS)_\* 1>nul
		RMDIR /Q $(<:BS)_
	}

	actions together ArchiveArchive
	{
		$(AR) /out:$(<) $(>)
	}

	actions As
	{
		$(AS) /Ml /p /v /w2 $(>) $(<) ,nul,nul;
	}

	actions Cc_
	{
		$(CC) /c /Fo$(<) $(CCFLAGS) $(CCDEFS) $(CCHDRS) /I$(STDHDRS) $(>)
	}

	actions C++_
	{
		$(C++) /c /Fo$(<) $(C++FLAGS) $(CCDEFS) $(CCHDRS) /I$(STDHDRS) /Tp $(>)
	}

	actions Link_ bind LINKOBJS LINKLIBS LINKSHLIBS
	{
		$(LINK) $(LINKFLAGS) $(P_LINKFLAGS) /out:$(<) $(UNDEFS) $(>) $(LINKOBJS) $(LINKLIBS) $(LINKSHLIBS) $(STDLIBS)
	}

	# Create DLL using export attribute
	actions ShLink_  bind SHLINKOBJS SHLINKLIBS SHLINKSHLIBS 
	{
		$(LINK) /DLL $(SHLINKFLAGS) /out:$(<[1]) $(>) $(SHLINKOBJS) $(SHLINKLIBS) $(SHLINKSHLIBS) $(SHSTDLIBS)
	}

	# Create DLL using .def file
	actions ShLinkDef_ bind SHLINKDEFFILE SHLINKOBJS SHLINKLIBS SHLINKSHLIBS 
	{
		$(LINK) /DLL /DEF:$(SHLINKDEFFILE) $(SHLINKFLAGS) /out:$(<[1]) $(>) $(SHLINKOBJS) $(SHLINKLIBS) $(SHLINKSHLIBS) $(SHSTDLIBS)
	}
}
else if $(NT) && $(MSVC)
{
	actions updated together piecemeal Archive
	{
		$(AR) $(<) -+$(>)
	}

	actions Cc_
	{
		$(CC) /c /Fo$(<) $(CCFLAGS) $(CCDEFS) $(CCHDRS) $(>)
	}

	actions C++_
	{
		$(C++) /c /Fo$(<) $(C++FLAGS) $(CCDEFS) $(CCHDRS) /Tp $(>)
	}

	actions Link_ bind LINKOBJS LINKLIBS LINKSHLIBS
	{
		$(LINK) $(LINKFLAGS) $(P_LINKFLAGS) /out:$(<) $(UNDEFS) $(>) $(LINKOBJS) $(LINKLIBS) $(LINKSHLIBS) $(STDLIBS)
	}
}
else if $(NT) && $(BCCROOT)
{
	actions updated together piecemeal Archive
	{
		$(AR) $(<) -+$(>)
	}

	actions Link_ bind LINKOBJS LINKLIBS LINKSHLIBS
	{
		$(LINK) -e$(<) $(LINKFLAGS) $(P_LINKFLAGS) $(UNDEFS) -L$(STDLIBS) $(LINKLIBS) $(LINKSHLIBS) $(>) $(LINKOBJS)
	}

	actions C++_
	{
		$(C++) -c -o$(<) $(C++FLAGS) $(CCDEFS) $(CCHDRS) $(>)
	}

	actions Cc_
	{
		$(CC) -c -o$(<) $(CCFLAGS) $(CCDEFS) $(CCHDRS) $(>)
	}
}

else if $(NT) && $(MINGW) {

	# Create DLL using export attribute
	actions ShLink_  bind SHLINKOBJS SHLINKLIBS SHLINKSHLIBS
	{
		$(LINK) -shared $(SHLINKFLAGS) $(LINKOUTFLAG)$(<[1]) -Wl,--out-implib,$(<[2]) $(>) $(SHLINKOBJS) $(SHLINKLIBS) $(SHLINKSHLIBS) $(SHSTDLIBS)
	}
	# Create DLL using .def file
	actions ShLinkDef_ bind SHLINKOBJS SHLINKLIBS SHLINKSHLIBS SHLINKDEFFILE
	{
		$(LINK) -shared $(SHLINKFLAGS) $(LINKOUTFLAG)$(<[1]) -Wl,--out-implib,$(<[2]) $(>) $(SHLINKOBJS) $(SHLINKLIBS) $(SHLINKSHLIBS) $(SHSTDLIBS) $(SHLINKDEFFILE)
	}
}

#
# OS2 specific actions
#

else if $(OS2) && $(WATCOM)
{
	actions together piecemeal Archive
	{
		$(AR) $(<) +-$(>) 
	}

	actions Cc_
	{
		$(CC) /Fo=$(<) $(CCFLAGS) $(CCDEFS) $(CCHDRS) $(>)
	}

	actions C++_
	{
		$(C++) /Fo=$(<) $(C++FLAGS) $(CCDEFS) $(CCHDRS) $(>)
	}

	actions Link_ bind LINKOBJS LINKLIBS LINKSHLIBS 
	{
		$(LINK) $(LINKFLAGS) $(P_LINKFLAGS) /Fe=$(<) $(UNDEFS) $(>) $(LINKOBJS) $(LINKLIBS) $(LINKSHLIBS) $(STDLIBS)
	}

	actions Shell_
	{
		$(CP) $(>) $(<)
	}
}

#
# VMS specific actions
#

else if $(VMS)
{
	actions updated together piecemeal Archive 
	{
		lib/replace $(<) $(>[1]) ,$(>[2-])
	}

	actions Cc_
	{ 
		$(CC)/obj=$(<) $(CCFLAGS) $(CCDEFS) $(CCHDRS) $(>) 
	}

	actions C++_
	{ 
		$(C++)/obj=$(<) $(C++FLAGS) $(CCDEFS) $(CCHDRS) $(>) 
	}

	actions piecemeal together existing Clean
	{
		$(RM) $(>[1]);* ,$(>[2-]);*
	}

	actions together quietly CreLib
	{
		if f$search("$(<)") .eqs. "" then lib/create $(<)
	}

	actions GenFile1
	{
		mcr $(>[1]) $(<) $(>[2-])
	}

	actions Link_ bind LINKOBJS LINKLIBS LINKSHLIBS
	{
		$(LINK)/exe=$(<) $(LINKFLAGS) $(P_LINKFLAGS) $(>:J=,) ,$(LINKOBJS:J=,) ,$(LINKLIBS)/lib ,$(LINKSHLIBS)/lib ,$(STDLIBS)
	}

	actions quietly updated piecemeal together RmTemps_
	{
		$(RM) $(>[1]);* ,$(>[2-]);*
	}

	actions Shell_
	{
		$(CP) $(>) $(<)
	}
}

#
# Mac specifc actions
#

else if $(MAC)
{
	actions together Archive 
	{
		$(LINK) -library -o $(<) $(>)
	}

	actions Cc_
	{
		set -e MWCincludes $(CCHDRS)
		$(CC) -o $(<) $(CCFLAGS) $(CCDEFS) $(>) 
	}

	actions C++_
	{
		set -e MWCincludes $(CCHDRS)
		$(CC) -o $(<) $(C++FLAGS) $(CCDEFS) $(>) 
	}

	actions Link_ bind LINKOBJS LINKLIBS LINKSHLIBS
	{
		$(LINK) -o $(<) $(LINKOBJS) $(LINKFLAGS) $(P_LINKFLAGS) $(>) $(LINKLIBS) $(LINKSHLIBS) "$(STDLIBS)"
	}
}

if $(WIN98)
{
	actions existing Clean
	{
		del $(>)
	}
}

# =========================================

# Now do Argyll init and read default Jamtop
DoInit ;

#
# Now include the user's Jamfile.
#

#PeerInclude $(DOT) ;
SubInclude $(DOT) ;