summaryrefslogtreecommitdiff
path: root/ghc/docs/users_guide/using.sgml
blob: 8d6d658536eb2fc272279133e5e36c73d2b01107 (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
<Chapter id="using-GHC">
<Title>Using GHC
</Title>

<Para>
<IndexTerm><Primary>GHC, using</Primary></IndexTerm>
<IndexTerm><Primary>using GHC</Primary></IndexTerm>
GHC is a command-line compiler: in order to compile a Haskell program,
GHC must be invoked on the source file(s) by typing a command to the
shell.  The steps involved in compiling a program can be automated
using the <Command>make</Command> tool (this is especially useful if the program
consists of multiple source files which depend on each other).  This
section describes how to use GHC from the command-line.
</Para>

<Sect1 id="command-line-structure">
<Title>Overall command-line structure
</Title>

<Para>
<IndexTerm><Primary>structure, command-line</Primary></IndexTerm>
<IndexTerm><Primary>command-line structure</Primary></IndexTerm>
</Para>

<Para>
An invocation of GHC takes the following form:
</Para>

<Para>

<Screen>
ghc [argument...]
</Screen>

</Para>

<Para>
Command-line arguments are either options or file names.
</Para>

<Para>
Command-line options begin with <Literal>-</Literal>.  They may <Emphasis>not</Emphasis> be
grouped: <Option>-vO</Option> is different from <Option>-v -O</Option>.  Options need not
precede filenames: e.g., <Command>ghc *.o -o foo</Command>.  All options are
processed and then applied to all files; you cannot, for example, invoke
<Command>ghc -c -O1 Foo.hs -O2 Bar.hs</Command> to apply different optimisation
levels to the files <Filename>Foo.hs</Filename> and <Filename>Bar.hs</Filename>.  For conflicting
options, e.g., <Option>-c -S</Option>, we reserve the right to do anything we
want.  (Usually, the last one applies.)
</Para>

</Sect1>

<Sect1 id="file-suffixes">
<Title>Meaningful file suffixes
</Title>

<Para>
<IndexTerm><Primary>suffixes, file</Primary></IndexTerm>
<IndexTerm><Primary>file suffixes for GHC</Primary></IndexTerm>
</Para>

<Para>
File names with &ldquo;meaningful&rdquo; suffixes (e.g., <Filename>.lhs</Filename> or <Filename>.o</Filename>)
cause the &ldquo;right thing&rdquo; to happen to those files.
</Para>

<Para>
<VariableList>

<VarListEntry>
<Term><Filename>.lhs</Filename>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>lhs suffix</Primary></IndexTerm>
A &ldquo;literate Haskell&rdquo; module.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Filename>.hs</Filename>:</Term>
<ListItem>
<Para>
A not-so-literate Haskell module.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Filename>.hi</Filename>:</Term>
<ListItem>
<Para>
A Haskell interface file, probably compiler-generated.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Filename>.hc</Filename>:</Term>
<ListItem>
<Para>
Intermediate C file produced by the Haskell compiler.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Filename>.c</Filename>:</Term>
<ListItem>
<Para>
A C&nbsp;file not produced by the Haskell compiler.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Filename>.s</Filename>:</Term>
<ListItem>
<Para>
An assembly-language source file, usually
produced by the compiler.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Filename>.o</Filename>:</Term>
<ListItem>
<Para>
An object file, produced by an assembler.
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

<Para>
Files with other suffixes (or without suffixes) are passed straight
to the linker.
</Para>

</Sect1>

<Sect1 id="options-help">
<Title>Help and verbosity options
</Title>

<Para>
<IndexTerm><Primary>help options (GHC)</Primary></IndexTerm>
<IndexTerm><Primary>verbose option (GHC)</Primary></IndexTerm>
</Para>

<Para>
A good option to start with is the <Option>-help</Option> (or <Option>-?</Option>) option.
<IndexTerm><Primary>-help option</Primary></IndexTerm>
<IndexTerm><Primary>-? option</Primary></IndexTerm>
GHC spews a long message to standard output and then exits.
</Para>

<Para>
The <Option>-v</Option><IndexTerm><Primary>-v option</Primary></IndexTerm> option makes GHC <Emphasis>verbose</Emphasis>: it
reports its version number and shows (on stderr) exactly how it invokes each
phase of the compilation system.  Moreover, it passes
the <Option>-v</Option> flag to most phases; each reports
its version number (and possibly some other information).
</Para>

<Para>
Please, oh please, use the <Option>-v</Option> option when reporting bugs!
Knowing that you ran the right bits in the right order is always the
first thing we want to verify.
</Para>

<Para>
If you're just interested in the compiler version number, the
<Option>--version</Option><IndexTerm><Primary>--version option</Primary></IndexTerm> option prints out a
one-line string containing the requested info.
</Para>

</Sect1>

<Sect1 id="options-order">
<Title>Running the right phases in the right order
</Title>

<Para>
<IndexTerm><Primary>order of passes in GHC</Primary></IndexTerm>
<IndexTerm><Primary>pass ordering in GHC</Primary></IndexTerm>
The basic task of the <Command>ghc</Command> driver is to run each input file
through the right phases (compiling, linking, etc.).
</Para>

<Para>
The first phase to run is determined by the input-file suffix, and the
last phase is determined by a flag.  If no relevant flag is present,
then go all the way through linking.  This table summarises:
</Para>

<Para>
<InformalTable>
<TGroup Cols="4">
<ColSpec Align="Left">
<ColSpec Align="Left">
<ColSpec Align="Left">
<ColSpec Align="Left">
<TBody>

<Row>
<Entry>Phase of the compilation system</Entry>
<Entry>Suffix saying &ldquo;start here&rdquo;</Entry>
<Entry>Flag saying &ldquo;stop after&rdquo;</Entry>
<Entry>(suffix of) output file</Entry>
</Row>

<Row>
<Entry>
literate pre-processor </Entry>
<Entry> .lhs </Entry>
<Entry> - </Entry>
<Entry> - </Entry>
</Row>
<Row>
<Entry>
C pre-processor (opt.) </Entry>
<Entry> - </Entry>
<Entry> - </Entry>
<Entry> - </Entry>
</Row>
<Row>
<Entry>
Haskell compiler </Entry>
<Entry> .hs </Entry>
<Entry> -C, -S </Entry>
<Entry> .hc, .s </Entry>
</Row>
<Row>
<Entry>
C compiler (opt.) </Entry>
<Entry> .hc or .c </Entry>
<Entry> -S </Entry>
<Entry> .s </Entry>
</Row>
<Row>
<Entry>
assembler </Entry>
<Entry> .s </Entry>
<Entry> -c </Entry>
<Entry> .o </Entry>
</Row>
<Row>
<Entry>
linker </Entry>
<Entry> other </Entry>
<Entry> - </Entry>
<Entry> a.out </Entry>
</Row>
</TBody>
</TGroup>
</InformalTable>

<IndexTerm><Primary>-C option</Primary></IndexTerm>
<IndexTerm><Primary>-S option</Primary></IndexTerm>
<IndexTerm><Primary>-c option</Primary></IndexTerm>
</Para>

<Para>
Thus, a common invocation would be: <Command>ghc -c Foo.hs</Command>
</Para>

<Para>
Note: What the Haskell compiler proper produces depends on whether a
native-code generator is used (producing assembly language) or not
(producing C).
</Para>

<Para>
The option <Option>-cpp</Option><IndexTerm><Primary>-cpp option</Primary></IndexTerm> must be given for the C
pre-processor phase to be run, that is, the pre-processor will be run
over your Haskell source file before continuing.
</Para>

<Para>
The option <Option>-E</Option><IndexTerm><Primary>-E option</Primary></IndexTerm> runs just the pre-processing
passes of the compiler, outputting the result on stdout before
stopping. If used in conjunction with -cpp, the output is the
code blocks of the original (literal) source after having put it
through the grinder that is the C pre-processor. Sans <Option>-cpp</Option>, the
output is the de-litted version of the original source.
</Para>

<Para>
The option <Option>-optcpp-E</Option><IndexTerm><Primary>-optcpp-E option</Primary></IndexTerm> runs just the
pre-processing stage of the C-compiling phase, sending the result to
stdout.  (For debugging or obfuscation contests, usually.)
</Para>

</Sect1>

<Sect1 id="options-output">
<Title>Re-directing the compilation output(s)
</Title>

<Para>
<IndexTerm><Primary>output-directing options</Primary></IndexTerm>
</Para>

<Para>
GHC's compiled output normally goes into a <Filename>.hc</Filename>, <Filename>.o</Filename>, etc., file,
depending on the last-run compilation phase.  The option <Option>-o
foo</Option><IndexTerm><Primary>-o option</Primary></IndexTerm> re-directs the output of that last-run
phase to file <Filename>foo</Filename>.
</Para>

<Para>
Note: this &ldquo;feature&rdquo; can be counterintuitive:
<Command>ghc -C -o foo.o foo.hs</Command> will put the intermediate C code in the
file <Filename>foo.o</Filename>, name notwithstanding!
</Para>

<Para>
EXOTICA: But the <Option>-o</Option> option isn't of much use if you have
<Emphasis>several</Emphasis> input files&hellip; Non-interface output files are
normally put in the same directory as their corresponding input file
came from.  You may specify that they be put in another directory
using the <Option>-odir &lt;dir&gt;</Option><IndexTerm><Primary>-odir &lt;dir&gt; option</Primary></IndexTerm> (the
&ldquo;Oh, dear&rdquo; option).  For example:
</Para>

<Para>

<Screen>
% ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch`
</Screen>

</Para>

<Para>
The output files, <Filename>Foo.o</Filename>, <Filename>Bar.o</Filename>, and <Filename>Bumble.o</Filename> would be
put into a subdirectory named after the architecture of the executing
machine (<Filename>sun4</Filename>, <Filename>mips</Filename>, etc).  The directory must already
exist; it won't be created.
</Para>

<Para>
Note that the <Option>-odir</Option> option does <Emphasis>not</Emphasis> affect where the
interface files are put.  In the above example, they would still be
put in <Filename>parse/Foo.hi</Filename>, <Filename>parse/Bar.hi</Filename>, and <Filename>gurgle/Bumble.hi</Filename>.
</Para>

<Para>
MORE EXOTICA: The <Option>-osuf &lt;suffix&gt;</Option><IndexTerm><Primary>-osuf &lt;suffix&gt;
option</Primary></IndexTerm> will change the <Filename>.o</Filename> file suffix for object files to
whatever you specify.  (We use this in compiling the prelude.).
Similarly, the <Option>-hisuf &lt;suffix&gt;</Option><IndexTerm><Primary>-hisuf &lt;suffix&gt;
option</Primary></IndexTerm> will change the <Filename>.hi</Filename> file suffix for non-system
interface files (see <XRef LinkEnd="hi-options">).
</Para>

<Para>
The <Option>-hisuf</Option>/<Option>-osuf</Option> game is useful if you want to compile a program
with both GHC and HBC (say) in the same directory.  Let HBC use the
standard <Filename>.hi</Filename>/<Filename>.o</Filename> suffixes; add <Option>-hisuf g&lowbar;hi -osuf g&lowbar;o</Option> to your
<Command>make</Command> rule for GHC compiling&hellip;
</Para>

    <sect2 id="keeping-intermediates">
      <title>Keeping Intermediate Files</title>
      <indexterm><primary>intermediate files, saving</primary>
      </indexterm>
      <indexterm><primary><literal>.hc</literal> files, saving</primary>
      </indexterm>
      <indexterm><primary><literal>.s</literal> files, saving</primary>
      </indexterm>

      <para>The following options are useful for keeping certain
      intermediate files around, when normally GHC would throw these
      away after compilation:</para>

      <variablelist>
	<varlistentry>
	  <term><literal>-keep-hc-files</literal></term>
	  <indexterm>
	    <primary><literal>-keep-hc-files</literal></primary>
	  </indexterm>
	  <listitem>
	    <para>Keep intermediate <literal>.hc</literal> files when
	    doing <literal>.hs</literal>-to-<literal>.o</literal>
	    compilations via C (NOTE: <literal>.hc</literal> files
	    aren't generated when using the native code generator, you
	    may need to use <literal>-fvia-C</literal> to force them
	    to be produced).</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>-keep-s-files</literal></term>
	  <indexterm>
	    <primary><literal>-keep-s-files</literal></primary>
	  </indexterm>
	  <listitem>
	    <para>Keep intermediate <literal>.s</literal> files.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>-keep-raw-s-files</literal></term>
	  <indexterm>
	    <primary><literal>-keep-raw-s-files</literal></primary>
	  </indexterm>
	  <listitem>
	    <para>Keep intermediate <literal>.raw-s</literal> files.
	    These are the direct output from the C compiler, before
	    GHC does &ldquo;assembly mangling&rdquo; to produce the
	    <literal>.s</literal> file.  Again, these are not produced
	    when using the native code generator.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>-keep-tmp-files</literal></term>
	  <indexterm>
	    <primary><literal>-keep-tmp-files</literal></primary>
	  </indexterm>
	  <indexterm>
	    <primary>temporary files</primary>
	    <secondary>keeping</secondary>
	  </indexterm>
	  <listitem>
	    <para>Instructs the GHC driver not to delete any of its
	    temporary files, which it normally keeps in
	    <literal>/tmp</literal> (or possibly elsewhere; see <xref
	    linkend="temp-files">).  Running GHC with
	    <literal>-v</literal> will show you what temporary files
	    were generated along the way.</para>
	  </listitem>
	</varlistentry>
      </variablelist>
    </sect2>

<Sect2 id="saving-ghc-stderr">
<Title>Saving GHC's standard error output
</Title>

<Para>
<IndexTerm><Primary>standard error, saving</Primary></IndexTerm>
</Para>

<Para>
Sometimes, you may cause GHC to be rather chatty on standard error;
with <Option>-v</Option>, for example.  You can instruct GHC to <Emphasis>append</Emphasis> this
output to a particular log file with a <Option>-odump &lt;blah&gt;</Option><IndexTerm><Primary>-odump
&lt;blah&gt; option</Primary></IndexTerm> option.
</Para>

</Sect2>

<Sect2 id="temp-files">
<Title>Redirecting temporary files
</Title>

      <indexterm>
	<primary>temporary files</primary>
	<secondary>redirecting</secondary>
      </indexterm>

<Para>
If you have trouble because of running out of space in
<Filename>/tmp</Filename> (or wherever your installation thinks
temporary files should go), you may use the <Option>-tmpdir
&lt;dir&gt;</Option><IndexTerm><Primary>-tmpdir &lt;dir&gt;
option</Primary></IndexTerm> option to specify an alternate directory.
For example, <Option>-tmpdir .</Option> says to put temporary files in
the current working directory.
</Para>

<Para>
Alternatively, use your <Constant>TMPDIR</Constant> environment
variable.<IndexTerm><Primary>TMPDIR environment
variable</Primary></IndexTerm> Set it to the name of the directory
where temporary files should be put.  GCC and other programs will
honour the <Constant>TMPDIR</Constant> variable as well.
</Para>

<Para>
Even better idea: Set the <Constant>TMPDIR</Constant> variable when building GHC, and
never worry about <Constant>TMPDIR</Constant> again. (see the build documentation).
</Para>

</Sect2>

</Sect1>

<Sect1 id="options-sanity">
<Title>Warnings and sanity-checking
</Title>

<Para>
<IndexTerm><Primary>sanity-checking options</Primary></IndexTerm>
<IndexTerm><Primary>warnings</Primary></IndexTerm>
GHC has a number of options that select which types of non-fatal error
messages, otherwise known as warnings, can be generated during
compilation.  By default, you get a standard set of warnings which are
generally likely to indicate bugs in your program.  These are:
<Option>-fwarn-overlpapping-patterns</Option>, <Option>-fwarn-duplicate-exports</Option>, and
<Option>-fwarn-missing-methods</Option>.  The following flags are simple ways to
select standard &ldquo;packages&rdquo; of warnings:
</Para>

<Para>
<VariableList>

<VarListEntry>
<Term><Option>-Wnot</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-Wnot option</Primary></IndexTerm>
Turns off all warnings, including the standard ones.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-w</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-w option</Primary></IndexTerm>
Synonym for <Option>-Wnot</Option>.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-W</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-W option</Primary></IndexTerm>
Provides the standard warnings plus <Option>-fwarn-incomplete-patterns</Option>,
<Option>-fwarn-unused-imports</Option> and <Option>-fwarn-unused-binds</Option>.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-Wall</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-Wall option</Primary></IndexTerm>
Turns on all warning options.
</Para>
</ListItem>
</VarListEntry>

</VariableList>
</Para>

<Para>
The full set of warning options is described below.  To turn off any
warning, simply give the corresponding <Option>-fno-warn-...</Option> option on
the command line.
</Para>

<Para>
<VariableList>

<VarListEntry>
<Term><Option>-fwarn-name-shadowing</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-name-shadowing option</Primary></IndexTerm>
<IndexTerm><Primary>shadowing, warning</Primary></IndexTerm>This option causes a warning to be emitted whenever an inner-scope
value has the same name as an outer-scope value, i.e. the inner value
shadows the outer one.  This can catch typographical errors that turn
into hard-to-find bugs, e.g., in the inadvertent cyclic definition
<Literal>let x = ... x ... in</Literal>.
</Para>

<Para>
Consequently, this option does <Emphasis>not</Emphasis> allow cyclic recursive
definitions.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fwarn-overlapping-patterns</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-overlapping-patterns option</Primary></IndexTerm>
<IndexTerm><Primary>overlapping patterns, warning</Primary></IndexTerm>
<IndexTerm><Primary>patterns, overlapping</Primary></IndexTerm>
By default, the compiler will warn you if a set of patterns are
overlapping, i.e.,
</Para>

<Para>
<ProgramListing>
f :: String -&#62; Int
f []     = 0
f (_:xs) = 1
f "2"    = 2
</ProgramListing>
</Para>

<Para>
where the last pattern match in <Function>f</Function> won't ever be reached, as the
second pattern overlaps it. More often than not, redundant patterns
is a programmer mistake/error, so this option is enabled by default.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fwarn-incomplete-patterns</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-incomplete-patterns option</Primary></IndexTerm>
<IndexTerm><Primary>incomplete patterns, warning</Primary></IndexTerm>
<IndexTerm><Primary>patterns, incomplete</Primary></IndexTerm>
Similarly for incomplete patterns, the function <Function>g</Function> below will fail
when applied to non-empty lists, so the compiler will emit a warning
about this when <Option>-fwarn-incomplete-patterns</Option> is enabled.
</Para>

<Para>
<ProgramListing>
g [] = 2
</ProgramListing>
</Para>

<Para>
This option isn't enabled be default because it can be a bit noisy,
and it doesn't always indicate a bug in the program.  However, it's
generally considered good practice to cover all the cases in your
functions.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fwarn-missing-methods</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-missing-methods option</Primary></IndexTerm>
<IndexTerm><Primary>missing methods, warning</Primary></IndexTerm>
<IndexTerm><Primary>methods, missing</Primary></IndexTerm>
This option is on by default, and warns you whenever an instance
declaration is missing one or more methods, and the corresponding
class declaration has no default declaration for them.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fwarn-missing-fields</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-missing-fields option</Primary></IndexTerm>
<IndexTerm><Primary>missing fields, warning</Primary></IndexTerm>
<IndexTerm><Primary>fields, missing</Primary></IndexTerm>
This option is on by default, and warns you whenever the construction
of a labelled field constructor isn't complete, missing initializers
for one or more fields. While not an error (the missing fields are
initialised with bottoms), it is often an indication of a programmer
error.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fwarn-unused-imports</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-unused-imports option</Primary></IndexTerm>
<IndexTerm><Primary>unused imports, warning</Primary></IndexTerm>
<IndexTerm><Primary>imports, unused</Primary></IndexTerm>
Report any objects that are explicitly imported but never used.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fwarn-unused-binds</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-unused-binds option</Primary></IndexTerm>
<IndexTerm><Primary>unused binds, warning</Primary></IndexTerm>
<IndexTerm><Primary>binds, unused</Primary></IndexTerm>
Report any function definitions (and local bindings) which are unused.
For top-level functions, the warning is only given if the binding is
not exported.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-fwarn-unused-matches</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-unused-matches option</Primary></IndexTerm>
<IndexTerm><Primary>unused matches, warning</Primary></IndexTerm>
<IndexTerm><Primary>matches, unused</Primary></IndexTerm>
Report all unused variables which arise from pattern matches,
including patterns consisting of a single variable.  For instance <Literal>f x
y = []</Literal> would report <VarName>x</VarName> and <VarName>y</VarName> as unused.  To eliminate the warning,
all unused variables can be replaced with wildcards.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fwarn-duplicate-exports</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-duplicate-exports option</Primary></IndexTerm>
<IndexTerm><Primary>duplicate exports, warning</Primary></IndexTerm>
<IndexTerm><Primary>export lists, duplicates</Primary></IndexTerm>
Have the compiler warn about duplicate entries in export lists. This
is useful information if you maintain large export lists, and want to
avoid the continued export of a definition after you've deleted (one)
mention of it in the export list.
</Para>

<Para>
This option is on by default.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fwarn-type-defaults</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-type-defaults option</Primary></IndexTerm>
<IndexTerm><Primary>defaulting mechanism, warning</Primary></IndexTerm>
Have the compiler warn/inform you where in your source the Haskell
defaulting mechanism for numeric types kicks in. This is useful
information when converting code from a context that assumed one
default into one with another, e.g., the `default default' for Haskell
1.4 caused the otherwise unconstrained value <Constant>1</Constant> to be given
the type <Literal>Int</Literal>, whereas Haskell 98 defaults it to
<Literal>Integer</Literal>.  This may lead to differences in performance and
behaviour, hence the usefulness of being non-silent about this.
</Para>

<Para>
This warning is off by default.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fwarn-missing-signatures</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fwarn-missing-signatures option</Primary></IndexTerm>
<IndexTerm><Primary>type signatures, missing</Primary></IndexTerm>
If you would like GHC to check that every top-level function/value has
a type signature, use the <Option>-fwarn-missing-signatures</Option> option.  This
option is off by default.
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

<Para>
If you're feeling really paranoid, the <Option>-dcore-lint</Option>
option<IndexTerm><Primary>-dcore-lint option</Primary></IndexTerm> is a good choice.  It turns on
heavyweight intra-pass sanity-checking within GHC.  (It checks GHC's
sanity, not yours.)
</Para>

</Sect1>

<Sect1 id="separate-compilation">
<Title>Separate compilation
</Title>

<Para>
<IndexTerm><Primary>separate compilation</Primary></IndexTerm>
<IndexTerm><Primary>recompilation checker</Primary></IndexTerm>
<IndexTerm><Primary>make and recompilation</Primary></IndexTerm>
This section describes how GHC supports separate compilation.
</Para>

<Sect2 id="hi-files">
<Title>Interface files
</Title>

<Para>
<IndexTerm><Primary>interface files</Primary></IndexTerm>
<IndexTerm><Primary>.hi files</Primary></IndexTerm>
</Para>

<Para>
When GHC compiles a source file <Filename>F</Filename> which contains a module <Literal>A</Literal>, say,
it generates an object <Filename>F.o</Filename>, <Emphasis>and</Emphasis> a companion <Emphasis>interface
file</Emphasis> <Filename>A.hi</Filename>.  The interface file is not intended for human
consumption, as you'll see if you take a look at one.  It's merely
there to help the compiler compile other modules in the same program.
</Para>

<Para>
NOTE: Having the name of the interface file follow the module name and
not the file name, means that working with tools such as <Command>make</Command>
become harder. <Command>make</Command> implicitly assumes that any output files
produced by processing a translation unit will have file names that
can be derived from the file name of the translation unit.  For
instance, pattern rules becomes unusable.  For this reason, we
recommend you stick to using the same file name as the module name.
</Para>

<Para>
The interface file for <Literal>A</Literal> contains information needed by the compiler
when it compiles any module <Literal>B</Literal> that imports <Literal>A</Literal>, whether directly or
indirectly.  When compiling <Literal>B</Literal>, GHC will read <Filename>A.hi</Filename> to find the
details that it needs to know about things defined in <Literal>A</Literal>.
</Para>

<Para>
Furthermore, when compiling module <Literal>C</Literal> which imports <Literal>B</Literal>, GHC may
decide that it needs to know something about <Literal>A</Literal>&mdash;for example, <Literal>B</Literal>
might export a function that involves a type defined in <Literal>A</Literal>.  In this
case, GHC will go and read <Command>A.hi</Command> even though <Literal>C</Literal> does not explicitly
import <Literal>A</Literal> at all.
</Para>

<Para>
The interface file may contain all sorts of things that aren't
explicitly exported from <Literal>A</Literal> by the programmer.  For example, even
though a data type is exported abstractly, <Filename>A.hi</Filename> will contain the
full data type definition.  For small function definitions, <Filename>A.hi</Filename>
will contain the complete definition of the function.  For bigger
functions, <Filename>A.hi</Filename> will contain strictness information about the
function.  And so on.  GHC puts much more information into <Filename>.hi</Filename> files
when optimisation is turned on with the <Option>-O</Option> flag.  Without <Option>-O</Option> it
puts in just the minimum; with <Option>-O</Option> it lobs in a whole pile of stuff.
<IndexTerm><Primary>optimsation, effect on .hi files</Primary></IndexTerm>
</Para>

<Para>
<Filename>A.hi</Filename> should really be thought of as a compiler-readable version of
<Filename>A.o</Filename>.  If you use a <Filename>.hi</Filename> file that wasn't generated by the same
compilation run that generates the <Filename>.o</Filename> file the compiler may assume
all sorts of incorrect things about <Literal>A</Literal>, resulting in core dumps and
other unpleasant happenings.
</Para>

</Sect2>

<Sect2 id="options-finding-imports">
<Title>Finding interface files
</Title>

<Para>
<IndexTerm><Primary>interface files, finding them</Primary></IndexTerm>
<IndexTerm><Primary>finding interface files</Primary></IndexTerm>
</Para>

<Para>
In your program, you import a module <Literal>Foo</Literal> by saying
<Literal>import Foo</Literal>.  GHC goes looking for an interface file, <Filename>Foo.hi</Filename>.
It has a builtin list of directories (notably including <Filename>.</Filename>) where
it looks.
</Para>

<Para>
<VariableList>

<VarListEntry>
<Term><Option>-i&lt;dirs&gt;</Option></Term>
<ListItem>
<Para>
<IndexTerm><Primary>-i&lt;dirs&gt; option</Primary></IndexTerm>This flag
prepends a colon-separated list of <Filename>dirs</Filename> to the &ldquo;import
directories&rdquo; list.
See also <XRef LinkEnd="recomp"> for the significance of using
relative and absolute pathnames in the <Option>-i</Option> list.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-i</Option></Term>
<ListItem>
<Para>
resets the &ldquo;import directories&rdquo; list back to nothing.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-fno-implicit-prelude</Option></Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fno-implicit-prelude option</Primary></IndexTerm>
GHC normally imports <Filename>Prelude.hi</Filename> files for you.  If you'd rather it
didn't, then give it a <Option>-fno-implicit-prelude</Option> option.  
The idea is that you can then import a Prelude of your own.  (But don't call it <Literal>Prelude</Literal>;
the Haskell module namespace is flat, and you must not conflict with any Prelude module.)
</Para>
<Para>
Even though you have not imported the Prelude, all the built-in syntax still refers to 
the built-in Haskell Prelude types and values, as specified by the Haskell Report.  
For example, the type <Literal>[Int]</Literal>
still means <Literal>Prelude.[] Int</Literal>; tuples continue to refer to the standard Prelude
tuples; the translation for list comprehensions continues to use <Literal>Prelude.map</Literal> etc.
</Para>
<Para> With one group of exceptions!  You may want to define your own numeric class hierarchy.
It completely defeats that purpose if the literal "1" means "<Literal>Prelude.fromInteger 1</Literal>",
which is what the Haskell Report specifies.  So the <Option>-fno-implicit-prelude</Option> flag causes
the following pieces of built-in syntax to refer to whatever is in scope, not the Prelude versions:
<ItemizedList>
<ListItem>
<Para>
Integer and fractional literals mean "<Literal>fromInteger 1</Literal>" and "<Literal>fromRational 3.2</Literal>",
not the Prelude-qualified versions; both in expressions and in patterns.
</Para>
</ListItem>
<ListItem>
<Para>
Negation (e.g. "<Literal>- (f x)</Literal>") means "<Literal>negate (f x)</Literal>" (not <Literal>Prelude.negate</Literal>).
</Para>
</ListItem>
<ListItem>
<Para>
In an n+k pattern, the standard Prelude <Literal>Ord</Literal> class is used for comparison, but the 
necessary subtraction uses 
whatever "<Literal>(-)</Literal>" is in scope (not "<Literal>Prelude.(-)</Literal>").
</Para>
</ListItem>
</ItemizedList>
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-I&lt;dir&gt;</Option></Term>
<ListItem>
<Para>
<IndexTerm><Primary>-I&lt;dir&gt; option</Primary></IndexTerm>
Once a Haskell module has been compiled to C (<Filename>.hc</Filename> file), you may
wish to specify where GHC tells the C compiler to look for <Filename>.h</Filename> files.
(Or, if you are using the <Option>-cpp</Option> option<IndexTerm><Primary>-cpp option</Primary></IndexTerm>, where
it tells the C pre-processor to look&hellip;)  For this purpose, use a <Option>-I</Option>
option in the usual C-ish way.
</Para>
</ListItem>
</VarListEntry>

</VariableList>
</Para>

</Sect2>

<Sect2 id="hi-options">
<Title>Other options related to interface files
</Title>

<Para>
<IndexTerm><Primary>interface files, options</Primary></IndexTerm>
The interface output may be directed to another file
<Filename>bar2/Wurble.iface</Filename> with the option <Option>-ohi bar2/Wurble.iface</Option><IndexTerm><Primary>-ohi
&lt;file&gt; option</Primary></IndexTerm> (not recommended).
</Para>

<Para>
To avoid generating an interface file at all, use a <Option>-nohi</Option>
option.<IndexTerm><Primary>-nohi option</Primary></IndexTerm>
</Para>

<Para>
The compiler does not overwrite an existing <Filename>.hi</Filename> interface file if
the new one is byte-for-byte the same as the old one; this is friendly
to <Command>make</Command>.  When an interface does change, it is often enlightening to
be informed.  The <Option>-hi-diffs</Option><IndexTerm><Primary>-hi-diffs option</Primary></IndexTerm> option will
make GHC run <Command>diff</Command> on the old and new <Filename>.hi</Filename> files. You can also
record the difference in the interface file itself, the
<Option>-keep-hi-diffs</Option><IndexTerm><Primary>-keep-hi-diffs</Primary></IndexTerm> option takes care of that.
</Para>

<Para>
The <Filename>.hi</Filename> files from GHC contain &ldquo;usage&rdquo; information which changes
often and uninterestingly.  If you really want to see these changes
reported, you need to use the
<Option>-hi-diffs-with-usages</Option><IndexTerm><Primary>-hi-diffs-with-usages option</Primary></IndexTerm>
option.
</Para>

<Para>
Interface files are normally jammed full of compiler-produced
<Emphasis>pragmas</Emphasis>, which record arities, strictness info, etc.  If you
think these pragmas are messing you up (or you are doing some kind of
weird experiment), you can tell GHC to ignore them with the
<Option>-fignore-interface-pragmas</Option><IndexTerm><Primary>-fignore-interface-pragmas
option</Primary></IndexTerm> option.
</Para>

<Para>
When compiling without optimisations on, the compiler is extra-careful
about not slurping in data constructors and instance declarations that
it will not need. If you believe it is getting it wrong and not
importing stuff which you think it should, this optimisation can be
turned off with <Option>-fno-prune-tydecls</Option> and <Option>-fno-prune-instdecls</Option>.
<IndexTerm><Primary>-fno-prune-tydecls option</Primary></IndexTerm><IndexTerm><Primary>-fno-prune-instdecls
option</Primary></IndexTerm>
</Para>

<Para>
See also <XRef LinkEnd="options-linker">, which describes how the linker finds standard
Haskell libraries.
</Para>

</Sect2>

<Sect2 id="recomp">
<Title>The recompilation checker
</Title>

<IndexTerm><Primary>recompilation checker</Primary></IndexTerm>

<Para>
<variablelist>
<VarListEntry>
<Term><Option>-recomp</Option></Term>
<IndexTerm><Primary><option>-recomp</option> option</Primary></IndexTerm>
<ListItem>
<Para>
(On by default) Turn on recompilation checking.  This will stop
compilation early, leaving an existing <filename>.o</filename> file in
place, if it can be determined that the module does not need to be
recompiled.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-no-recomp</Option></Term>
<IndexTerm><Primary><option>-recomp</option> option</Primary></IndexTerm>
<ListItem>
<Para>
Turn off recompilation checking.
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

<Para>
In the olden days, GHC compared the newly-generated
<Filename>.hi</Filename> file with the previous version; if they were
identical, it left the old one alone and didn't change its
modification date.  In consequence, importers of a module with an
unchanged output <Filename>.hi</Filename> file were not recompiled.
</Para>

<Para>
This doesn't work any more.  In our earlier example, module
<Literal>C</Literal> does not import module <Literal>A</Literal>
directly, yet changes to <Filename>A.hi</Filename> should force a
recompilation of <Literal>C</Literal>.  And some changes to
<Literal>A</Literal> (changing the definition of a function that
appears in an inlining of a function exported by <Literal>B</Literal>,
say) may conceivably not change <Filename>B.hi</Filename> one jot.  So
now&hellip;
</Para>

<Para>
GHC keeps a version number on each interface file, and on each type
signature within the interface file.  It also keeps in every interface
file a list of the version numbers of everything it used when it last
compiled the file.  If the source file's modification date is earlier
than the <Filename>.o</Filename> file's date (i.e. the source hasn't
changed since the file was last compiled), and the
<option>-recomp</option> is given on the command line, GHC will be
clever.  It compares the version numbers on the things it needs this
time with the version numbers on the things it needed last time
(gleaned from the interface file of the module being compiled); if
they are all the same it stops compiling rather early in the process
saying &ldquo;Compilation IS NOT required&rdquo;.  What a beautiful
sight!
</Para>

<Para>
Patrick Sansom had a workshop paper about how all this is done (though
the details have changed quite a bit). <ULink URL="mailto:sansom@dcs.gla.ac.uk">Ask him</ULink> if you want a copy.
</Para>

</Sect2>


<Sect2 id="using-make">
<Title>Using <Command>make</Command>
</Title>

<Para>
<IndexTerm><Primary><literal>make</literal></Primary></IndexTerm>
</Para>

<Para>
It is reasonably straightforward to set up a <Filename>Makefile</Filename> to use with GHC, assuming you name your source files the same as your modules.
Thus:
</Para>

<Para>

<ProgramListing>
HC      = ghc
HC_OPTS = -cpp $(EXTRA_HC_OPTS)

SRCS = Main.lhs Foo.lhs Bar.lhs
OBJS = Main.o   Foo.o   Bar.o

.SUFFIXES : .o .hs .hi .lhs .hc .s

cool_pgm : $(OBJS)
        rm $@
        $(HC) -o $@ $(HC_OPTS) $(OBJS)

# Standard suffix rules
.o.hi:
        @:

.lhs.o:
        $(HC) -c $&#60; $(HC_OPTS)

.hs.o:
        $(HC) -c $&#60; $(HC_OPTS)

# Inter-module dependencies
Foo.o Foo.hc Foo.s    : Baz.hi          # Foo imports Baz
Main.o Main.hc Main.s : Foo.hi Baz.hi   # Main imports Foo and Baz
</ProgramListing>

</Para>

<Para>
(Sophisticated <Command>make</Command> variants may achieve some of the above more
elegantly.  Notably, <Command>gmake</Command>'s pattern rules let you write the more
comprehensible:
</Para>

<Para>

<ProgramListing>
%.o : %.lhs
        $(HC) -c $&#60; $(HC_OPTS)
</ProgramListing>

</Para>

<Para>
What we've shown should work with any <Command>make</Command>.)
</Para>

<Para>
Note the cheesy <Literal>.o.hi</Literal> rule: It records the dependency of the
interface (<Filename>.hi</Filename>) file on the source.  The rule says a <Filename>.hi</Filename> file can
be made from a <Filename>.o</Filename> file by doing&hellip;nothing.  Which is true.
</Para>

<Para>
Note the inter-module dependencies at the end of the Makefile, which
take the form
</Para>

<Para>

<ProgramListing>
Foo.o Foo.hc Foo.s    : Baz.hi          # Foo imports Baz
</ProgramListing>

</Para>

<Para>
They tell <Command>make</Command> that if any of <Literal>Foo.o</Literal>, <Literal>Foo.hc</Literal> or <Literal>Foo.s</Literal> have an
earlier modification date than <Literal>Baz.hi</Literal>, then the out-of-date file
must be brought up to date.  To bring it up to date, <Literal>make</Literal> looks for
a rule to do so; one of the preceding suffix rules does the job
nicely.
</Para>

    </sect2>

    <sect2 id="sec-makefile-dependencies">
      <title>Dependency generation</title>
      <indexterm><primary>dependencies in Makefiles</primary></indexterm>
      <indexterm><primary>Makefile dependencies</primary></indexterm>

      <para>Putting inter-dependencies of the form <Literal>Foo.o :
      Bar.hi</Literal> into your <Filename>Makefile</Filename> by hand
      is rather error-prone.  Don't worry, GHC has support for
      automatically generating the required dependencies.  Add the
      following to your <Filename>Makefile</Filename>:</para>

<ProgramListing>
depend :
        ghc -M $(HC_OPTS) $(SRCS)
</ProgramListing>

      <para>Now, before you start compiling, and any time you change
      the <Literal>imports</Literal> in your program, do <Command>make
      depend</Command> before you do <Command>make
      cool&lowbar;pgm</Command>.  <Command>ghc -M</Command> will append
      the needed dependencies to your
      <Filename>Makefile</Filename>.</Para>

      <para>In general, if module <Literal>A</Literal> contains the
      line

<programlisting>
import B ...blah...
</programlisting>

       then <command>ghc -M</command> will generate a dependency
       line of the form:

<programlisting>
A.o : B.hi
</programlisting>

       If module <literal>A</literal> contains the line 

<programlisting>
import {-# SOURCE #-} B ...blah...
</programlisting>

       then <command>ghc -M</command> will generate a dependency
       line of the form:

<programlisting>
A.o : B.hi-boot
</programlisting>

       (See <xref linkend="hi-files"> for details of interface files.)
       If <literal>A</literal> imports multiple modules, then there
       will be multiple lines with <filename>A.o</filename> as the
       target.</para>

      <para>By default, <Command>ghc -M</Command> generates all the
      dependencies, and then concatenates them onto the end of
      <Filename>makefile</Filename> (or <Filename>Makefile</Filename>
      if <Filename>makefile</Filename> doesn't exist) bracketed by the
      lines "<Literal>&num; DO NOT DELETE: Beginning of Haskell
      dependencies</Literal>" and "<Literal>&num; DO NOT DELETE: End
      of Haskell dependencies</Literal>".  If these lines already
      exist in the <Filename>makefile</Filename>, then the old
      dependencies are deleted first.</para>

      <para>Internally, GHC uses a script to generate the
      dependencies, called <command>mkdependHS</command>.  This script
      has some options of its own, which you might find useful.
      Options can be passed directly to <command>mkdependHS</command>
      with GHC's <literal>-optdep</literal> option.  For example, to
      generate the dependencies into a file called
      <literal>.depend</literal> instead of
      <literal>Makefile</literal>:</para>

<screen>
ghc -M -optdep-f optdep.depend ...
</screen>
      
      <para>The full list of options accepted by
      <command>mkdependHS</command> is:</para>

      <variablelist>

	<varlistentry>
	  <term><option>-w</option></term>
	  <listitem>
	    <para>Turn off warnings about interface file shadowing.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>-f blah</option></term>
	  <listitem>
	    <para>Use <Filename>blah</Filename> as the makefile,
            rather than <Filename>makefile</Filename> or
            <Filename>Makefile</Filename>.  If
            <Filename>blah</Filename> doesn't exist,
            <Command>mkdependHS</Command> creates it.  We often use
            <Option>-f .depend</Option> to put the dependencies in
            <Filename>.depend</Filename> and then
            <Command>include</Command> the file
            <Filename>.depend</Filename> into
            <Filename>Makefile</Filename>.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>-o &lt;osuf&gt;</option></term>
	  <listitem>
	    <para>Use <Filename>.&lt;osuf&gt;</Filename> as the
            "target file" suffix ( default: <Literal>o</Literal>).
            Multiple <Option>-o</Option> flags are permitted (GHC2.05
            onwards).  Thus "<Option>-o hc -o o</Option>" will
            generate dependencies for <Filename>.hc</Filename> and
            <Filename>.o</Filename> files.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>-s &lt;suf&gt;</option></term>
	  <listitem>
	    <para>Make extra dependencies that declare that files with
            suffix
            <Filename>.&lt;suf&gt;&lowbar;&lt;osuf&gt;</Filename>
            depend on interface files with suffix
            <Filename>.&lt;suf&gt;&lowbar;hi</Filename>, or (for
            <Literal>&lcub;-&num; SOURCE &num;-&rcub;</Literal>
            imports) on <Filename>.hi-boot</Filename>.  Multiple
            <Option>-s</Option> flags are permitted.  For example,
            <Option>-o hc -s a -s b</Option> will make dependencies
            for <Filename>.hc</Filename> on <Filename>.hi</Filename>,
            <Filename>.a&lowbar;hc</Filename> on
            <Filename>.a&lowbar;hi</Filename>, and
            <Filename>.b&lowbar;hc</Filename> on
            <Filename>.b&lowbar;hi</Filename>.  (Useful in conjunction
            with NoFib "ways".)</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>--exclude-module=&lt;file&gt;</option></term>
	  <listitem>
	    <para>Regard <Filename>&lt;file&gt;</Filename> as
            "stable"; i.e., exclude it from having dependencies on
            it.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>-x</option></term>
	  <listitem>
	    <para>same as <option>--exclude-module</option></para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>--exclude-directory=&lt;dirs&gt;</option></term>
	  <listitem>
	    <para>Regard the colon-separated list of directories
            <Filename>&lt;dirs&gt;</Filename> as containing stable,
            don't generate any dependencies on modules therein.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>-xdirs</option></term>
	  <listitem>
	    <para>same as <Option>--exclude-directory</Option>.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>--include-module=&lt;file&gt;</option></term>
	  <listitem>
	    <para>Regard <Filename>&lt;file&gt;</Filename> as not
            "stable"; i.e., generate dependencies on it (if any). This
            option is normally used in conjunction with the
            <Option>--exclude-directory</Option> option.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>--include-prelude</option></term>
	  <listitem>
	    <para>Regard prelude libraries as unstable, i.e., generate
            dependencies on the prelude modules used (including
            <Literal>Prelude</Literal>).  This option is normally only
            used by the various system libraries. If a
            <Option>-package</Option> option is used, dependencies will
            also be generated on the library's interfaces.</para>
	  </listitem>
	</varlistentry>
      </variablelist>

</Sect2>

<Sect2 id="mutual-recursion">
<Title>How to compile mutually recursive modules
</Title>

<Para>
<IndexTerm><Primary>module system, recursion</Primary></IndexTerm>
<IndexTerm><Primary>recursion, between modules</Primary></IndexTerm>
</Para>

<Para>
Currently, the compiler does not have proper support for dealing with
mutually recursive modules:
</Para>

<Para>

<ProgramListing>
module A where

import B

newtype TA = MkTA Int

f :: TB -&#62; TA
f (MkTB x) = MkTA x
--------
module B where

import A

data TB = MkTB !Int

g :: TA -&#62; TB
g (MkTA x) = MkTB x
</ProgramListing>

</Para>

<Para>
When compiling either module A and B, the compiler will try (in vain)
to look for the interface file of the other. So, to get mutually
recursive modules off the ground, you need to hand write an interface
file for A or B, so as to break the loop.  These hand-written
interface files are called <Literal>hi-boot</Literal> files, and are placed in a file
called <Filename>&lt;module&gt;.hi-boot</Filename>.  To import from an <Literal>hi-boot</Literal> file instead
of the standard <Filename>.hi</Filename> file, use the following syntax in the importing module:
<IndexTerm><Primary>hi-boot files</Primary></IndexTerm>
<IndexTerm><Primary>importing, hi-boot files</Primary></IndexTerm>
</Para>

<Para>

<ProgramListing>
import {-# SOURCE #-} A
</ProgramListing>

</Para>

<Para>
The hand-written interface need only contain the bare minimum of
information needed to get the bootstrapping process started.  For
example, it doesn't need to contain declarations for <Emphasis>everything</Emphasis>
that module <Literal>A</Literal> exports, only the things required by the module that
imports <Literal>A</Literal> recursively.
</Para>

<Para>
For the example at hand, the boot interface file for A would look like
the following:
</Para>

<Para>

<ProgramListing>
__interface A 1 404 where
__export A TA{MkTA} ;
1 newtype TA = MkTA PrelBase.Int ;
</ProgramListing>

</Para>

<Para>
The syntax is essentially the same as a normal <Filename>.hi</Filename> file
(unfortunately), but you can usually tailor an existing <Filename>.hi</Filename> file to
make a <Filename>.hi-boot</Filename> file.
</Para>

<Para>
Notice that we only put the declaration for the newtype <Literal>TA</Literal> in the
<Literal>hi-boot</Literal> file, not the signature for <Function>f</Function>, since <Function>f</Function> isn't used by
<Literal>B</Literal>.
</Para>

<Para>
The number &ldquo;1&rdquo; after &ldquo;&lowbar;&lowbar;interface A&rdquo; gives the version number of module A;
it is incremented whenever anything in A's interface file changes.  The &ldquo;404&rdquo; is
the version number of the interface file <Emphasis>syntax</Emphasis>; we change it when
we change the syntax of interface files so that you get a better error message when
you try to read an old-format file with a new-format compiler.
</Para>

<Para>
The number &ldquo;1&rdquo; at the beginning of a declaration is the <Emphasis>version
number</Emphasis> of that declaration: for the purposes of <Filename>.hi-boot</Filename> files
these can all be set to 1.  All names must be fully qualified with the
<Emphasis>original</Emphasis> module that an object comes from: for example, the
reference to <Literal>Int</Literal> in the interface for <Literal>A</Literal> comes from <Literal>PrelBase</Literal>,
which is a module internal to GHC's prelude.  It's a pain, but that's
the way it is.
</Para>

<Para>
If you want an hi-boot file to export a data type, but you don't want to give its constructors
(because the constructors aren't used by the SOURCE-importing module), you can write simply:
</Para>

<Para>

<ProgramListing>
__interface A 1 404 where
__export A TA;
1 data TA
</ProgramListing>

</Para>

<Para>
(You must write all the type parameters, but leave out the '=' and everything that follows it.)
</Para>

<Para>
<Emphasis>Note:</Emphasis> This is all a temporary solution, a version of the
compiler that handles mutually recursive modules properly without the manual
construction of interface files, is (allegedly) in the works.
</Para>

</Sect2>

</Sect1>

  <sect1 id="packages">
    <title>Packages</title>
    <indexterm><primary>packages</primary></indexterm>

    <para>Packages are collections of libraries, conveniently grouped
    together as a single entity.  The package system is flexible: a
    package may consist of Haskell code, foreign language code (eg. C
    libraries), or a mixture of the two.  A package is a good way to
    group together related Haskell modules, and is essential if you
    intend to make the modules into a Windows DLL (see below).</para>

    <para>Because packages can contain both Haskell and C libraries, they
    are also a good way to provide convenient access to a Haskell
    layer over a C library.</para>

    <para>GHC comes with several packages (see <xref
    linkend="book-hslibs">), and packages can be added/removed from an
    existing GHC installation.</para>

    <sect2 id="listing-packages">
      <title>Listing the available packages</title>
      <indexterm><primary>packages</primary>
	<secondary>listing</secondary></indexterm>

      <para>To see what packages are currently installed, use the
      <literal>--list-packages</literal> option:</para>
      <indexterm><primary><literal>--list-packages</literal></primary>
      </indexterm>

<screen>
  $ ghc --list-packages
  gmp, rts, std, lang, concurrent, data, net, posix, text, util
</screen>

      <para>Note that your GHC installation might have a slightly
      different set of packages installed.</para>

      <para>The <literal>gmp</literal> and <literal>rts</literal>
      packages are always present, and represent the multi-precision
      integer and runtime system libraries respectively.  The
      <literal>std</literal> package contains the Haskell prelude.
      The rest of the packages are optional libraries.</para>

    </sect2>

    <sect2 id="using-packages">
      <title>Using a package</title>
      <indexterm><primary>packages</primary>
	<secondary>using</secondary></indexterm>
      
      <para>To use a package, add the <literal>-package</literal> flag
      to the command line:</para>

      <variablelist>
	<varlistentry>
	  <term><option>-package &lt;lib&gt;</option></term>
	  <indexterm><primary>-package &lt;lib&gt; option</primary></indexterm>
	  <listitem>
	    <para>This option brings into scope all the modules from
	    package <literal>&lt;lib&gt;</literal> (they still have to
	    be imported in your Haskell source, however).  It also
	    causes the relevant libraries to be linked when linking is
	    being done.</para>
	  </listitem>
	</varlistentry>
      </variablelist>

      <para>Some packages depend on other packages, for example the
      <literal>text</literal> package makes use of some of the modules
      in the <literal>lang</literal> package.  The package system
      takes care of all these dependencies, so that when you say
      <literal>-package text</literal> on the command line, you
      automatically get <literal>-package lang</literal> too.</para>
    </sect2>

    <sect2 id="building-packages">
      <title>Building a package from Haskell source</title>
      <indexterm><primary>packages</primary>
	<secondary>building</secondary></indexterm>

      <para>It takes some special considerations to build a new
      package:</para>

      <itemizedlist>
	<listitem>
	  <para>A package may contain several Haskell modules. A
          package may span many directories, or many packages may
          exist in a single directory. Packages may not be mutually
          recursive.</para>
	</listitem>

	<listitem>
	  <para>A package has a name
  	  (e.g. <filename>std</filename>)</para>
	</listitem>

	<listitem>
	  <para>The Haskell code in a package may be built into one or
	  more Unix libraries (e.g. <Filename>libHSfoo.a</Filename>),
	  or a single DLL on Windows
	  (e.g. <Filename>HSfoo.dll</Filename>).  The restriction to a
	  single DLL on Windows is that the package system is used to
	  tell the compiler when it should make an inter-DLL call
	  rather than an intra-DLL call (inter-DLL calls require an
	  extra indirection).</para>
	</listitem>

	<listitem>
	  <para>GHC does not maintain detailed cross-package
          dependency information.  It does remember which modules in
          other packages the current module depends on, but not which
          things within those imported things.</para>
	</listitem>
      </itemizedlist>

      <para>To compile a module which is to be part of a new package,
      use the <literal>-package-name</literal> option:</para>

      <variablelist>
	<varlistentry>
	  <term><option>-package-name &lt;foo&gt;</option></term>
	  <indexterm><primary><literal>-package-name</literal></primary>
	    <secondary>option</secondary></indexterm>
	  <listitem>
	    <para>This option is added to the command line when
	    compiling a module that is destined to be part of package
	    <literal>foo</literal>.  If this flag is omitted then the
	    default package <literal>Main</literal> is assumed.</para>
	  </listitem>
	</varlistentry>
      </variablelist>

      <para>Failure to use the <literal>-package-name</literal> option
      when compiling a package will result in disaster on Windows, but
      is relatively harmless on Unix at the moment (it will just cause
      a few extra dependencies in some interface files).  However,
      bear in mind that we might add support for Unix shared libraries
      at some point in the future.</para>

      <para>It is worth noting that on Windows, because each package
      is built as a DLL, and a reference to a DLL costs an extra
      indirection, intra-package references are cheaper than
      inter-package references. Of course, this applies to the
      <Filename>Main</Filename> package as well.</para>

    </sect2>
    <sect2 id="package-management">
      <title>Package management</title>
      <indexterm><primary>packages</primary>
	<secondary>management</secondary></indexterm>
      
      <para>GHC uses a package configuration file, called
      <literal>packages.conf</literal>, which can be found in your GHC
      install directory.  This file isn't intended to be edited
      directly, instead GHC provides options for adding & removing
      packages:</para>

      <variablelist>
	<varlistentry>
	  <term><option>--add-package</option></term>
	  <indexterm><primary><literal>--add-package</literal></primary>
	      <secondary>option</secondary></indexterm>
	  <listitem>
	    <para>Reads a package specification (see below) on stdin,
	    and adds it to the database of installed packages.  The
	    package specification must be a package that isn't already
	    installed.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><option>--delete-package &lt;foo&gt;</option></term>
	  <indexterm><primary><literal>--delete-package</literal></primary>
	      <secondary>option</secondary></indexterm>
	  <listitem>
	    <para>Removes the specified package from the installed
	    configuration.</para>
	  </listitem>
	</varlistentry>
      </variablelist>

      <para>In both cases, the old package configuration file is saved
      in <literal>packages.conf.old</literal> in your GHC install
      directory, so in an emergency you can always copy this file into
      <literal>package.conf</literal> to restore the old
      settings.</para>

      <para>A package specification looks like this:</para>

<screen>
  Package {
     name            = "mypkg",
     import_dirs     = ["/usr/local/lib/imports/mypkg"],
     library_dirs    = ["/usr/local/lib"],
     hs_libraries    = ["HSmypkg" ],
     extra_libraries = ["HSmypkg_cbits"],
     include_dirs    = [],
     c_includes      = ["HsMyPkg.h"],
     package_deps    = ["text", "data"],
     extra_ghc_opts  = [],
     extra_cc_opts   = [],
     extra_ld_opts   = ["-lmy_clib"]
  }
</screen>

      <para>Components of a package specification may be specified in
      any order, and are:</para>

      <variablelist>
	<varlistentry>
	  <term><literal>name</literal></term>
	  <indexterm><primary><literal>name</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
            <para>The package's name, for use with
            the <literal>-package</literal> flag and as listed in the
            <literal>--list-packages</literal> list. 
            </para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>import_dirs</literal></term>
	  <indexterm><primary><literal>import_dirs</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>A list of directories containing interface files
	    (<literal>.hi</literal> files) for this package.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>library_dirs</literal></term>
	  <indexterm><primary><literal>library_dirs</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>A list of directories containing libraries for this
	    package.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>hs_libraries</literal></term>
	  <indexterm><primary><literal>hs_libraries</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>A list of libraries containing Haskell code for this
	    package, with the <literal>.a</literal> or
	    <literal>.dll</literal> suffix omitted.  On Unix, the
	    <literal>lib</literal> prefix is also omitted.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>extra_libraries</literal></term>
	  <indexterm><primary><literal>extra_libraries</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>A list of extra libraries for this package.  The
	    difference between <literal>hs_libraries</literal> and
	    <literal>extra_libraries</literal> is that
	    <literal>hs_libraries</literal> normally have several
	    versions, to support profiling, parallel and other build
	    options.  The various versions are given different
	    suffixes to distinguish them, for example the profiling
	    version of the standard prelude library is named
	    <filename>libHSstd_p.a</filename>, with the
	    <literal>_p</literal> indicating that this is a profiling
	    version.  The suffix is added automatically by GHC for
	    <literal>hs_libraries</literal> only, no suffix is added
	    for libraries in
	    <literal>extra_libraries</literal>.</para>

	    <para>Also, <literal>extra_libraries</literal> are placed
	    on the linker command line before the
	    <literal>hs_libraries</literal> for the same package.  If
	    your package has dependencies in the other direction, you
	    might need to make two separate packages.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>include_dirs</literal></term>
	  <indexterm><primary><literal>include_dirs</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>A list of directories containing C includes for this
	    package (maybe the empty list).</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>c_includes</literal></term>
	  <indexterm><primary><literal>c_includes</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>A list of files to include for via-C compilations
	    using this package.  Typically this include file will
	    contain function prototypes for any C functions used in
	    the package, in case they end up being called as a result
	    of Haskell functions from the package being
	    inlined.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>package_deps</literal></term>
	  <indexterm><primary><literal>package_deps</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>A list of packages which this package depends
	    on.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>extra_ghc_opts</literal></term>
	  <indexterm><primary><literal>extra_ghc_opts</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>Extra arguments to be added to the GHC command line
	    when this package is being used.</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>extra_cc_opts</literal></term>
	  <indexterm><primary><literal>extra_cc_opts</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>Extra arguments to be added to the gcc command line
	    when this package is being used (only for via-C
	    compilations).</para>
	  </listitem>
	</varlistentry>

	<varlistentry>
	  <term><literal>extra_ld_opts</literal></term>
	  <indexterm><primary><literal>extra_ld_opts</literal></primary>
	    <secondary>package specification</secondary></indexterm>
	  <listitem>
	    <para>Extra arguments to be added to the gcc command line
	    (for linking) when this package is being used.</para>
	  </listitem>
	</varlistentry>
      </variablelist>

      <para>For examples of more package specifications, take a look
      at the <literal>package.conf</literal> in your GHC
      installation.</para>
    </sect2>
  </sect1>


<Sect1 id="options-optimise">
<Title>Optimisation (code improvement)
</Title>

<Para>
<IndexTerm><Primary>optimisation (GHC)</Primary></IndexTerm>
<IndexTerm><Primary>improvement, code (GHC)</Primary></IndexTerm>
</Para>

<Para>
The <Option>-O*</Option> options specify convenient &ldquo;packages&rdquo; of optimisation
flags; the <Option>-f*</Option> options described later on specify
<Emphasis>individual</Emphasis> optimisations to be turned on/off; the <Option>-m*</Option>
options specify <Emphasis>machine-specific</Emphasis> optimisations to be turned
on/off.
</Para>

<Sect2 id="optimise-pkgs">
<Title><Option>-O*</Option>: convenient &ldquo;packages&rdquo; of optimisation flags.
</Title>

<Para>
<IndexTerm><Primary>-O options</Primary></IndexTerm>
</Para>

<Para>
There are <Emphasis>many</Emphasis> options that affect the quality of code
produced by GHC.  Most people only have a general goal, something like
&ldquo;Compile quickly&rdquo; or &ldquo;Make my program run like greased lightning.&rdquo;
The following &ldquo;packages&rdquo; of optimisations (or lack thereof) should
suffice.
</Para>

<Para>
Once you choose a <Option>-O*</Option> &ldquo;package,&rdquo; stick with it&mdash;don't chop and
change.  Modules' interfaces <Emphasis>will</Emphasis> change with a shift to a new
<Option>-O*</Option> option, and you may have to recompile a large chunk of all
importing modules before your program can again be run
safely (see <XRef LinkEnd="recomp">).
</Para>

<Para>
<VariableList>

<VarListEntry>
<Term>No <Option>-O*</Option>-type option specified:</Term>
<IndexTerm><Primary>-O* not specified</Primary></IndexTerm>
<ListItem>
<Para>
This is taken to mean: &ldquo;Please compile quickly; I'm not over-bothered
about compiled-code quality.&rdquo;  So, for example: <Command>ghc -c Foo.hs</Command>
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-O</Option> or <Option>-O1</Option>:</Term>
<IndexTerm><Primary>-O option</Primary></IndexTerm>
<IndexTerm><Primary>-O1 option</Primary></IndexTerm>
<IndexTerm><Primary>optimise</Primary><secondary>normally</secondary></IndexTerm>
<ListItem>
<Para>
Means: &ldquo;Generate good-quality code without taking too long about
it.&rdquo; Thus, for example: <Command>ghc -c -O Main.lhs</Command>
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-O2</Option>:</Term>
<IndexTerm><Primary>-O2 option</Primary></IndexTerm>
<IndexTerm><Primary>optimise</Primary><secondary>aggressively</secondary></IndexTerm>
<ListItem>
<Para>
Means: &ldquo;Apply every non-dangerous optimisation, even if it means
significantly longer compile times.&rdquo;
</Para>

<Para>
The avoided &ldquo;dangerous&rdquo; optimisations are those that can make
runtime or space <Emphasis>worse</Emphasis> if you're unlucky.  They are
normally turned on or off individually.
</Para>

<Para>
At the moment, <Option>-O2</Option> is <Emphasis>unlikely</Emphasis> to produce
better code than <Option>-O</Option>.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-O2-for-C</Option>:</Term>
<IndexTerm><Primary>-O2-for-C option</Primary></IndexTerm>
<IndexTerm><Primary>gcc, invoking with -O2</Primary></IndexTerm>
<ListItem>
<Para>
Says to run GCC with <Option>-O2</Option>, which may be worth a few percent in
execution speed.  Don't forget <Option>-fvia-C</Option>, lest you use the native-code
generator and bypass GCC altogether!
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-Onot</Option>:</Term>
<IndexTerm><Primary>-Onot option</Primary></IndexTerm>
<IndexTerm><Primary>optimising, reset</Primary></IndexTerm>
<ListItem>
<Para>
This option will make GHC &ldquo;forget&rdquo; any
<Option>-O</Option>ish options it has seen so far.  Sometimes useful;
for example: <Command>make all
EXTRA&lowbar;HC&lowbar;OPTS=-Onot</Command>.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-Ofile &lt;file&gt;</Option>:</Term>
<IndexTerm><Primary>-Ofile &lt;file&gt; option</Primary></IndexTerm>
<IndexTerm><Primary>optimising, customised</Primary></IndexTerm>
<ListItem>
<Para>
For those who need <Emphasis>absolute</Emphasis> control over
<Emphasis>exactly</Emphasis> what options are used (e.g., compiler
writers, sometimes :-), a list of options can be put in a file and
then slurped in with <Option>-Ofile</Option>.
</Para>

<Para>
In that file, comments are of the
<Literal>&num;</Literal>-to-end-of-line variety; blank lines and most
whitespace is ignored.
</Para>

<Para>
Please ask if you are baffled and would like an example of <Option>-Ofile</Option>!
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

<Para>
At Glasgow, we don't use a <Option>-O*</Option> flag for day-to-day work.  We use
<Option>-O</Option> to get respectable speed; e.g., when we want to measure
something.  When we want to go for broke, we tend to use <Option>-O -fvia-C
-O2-for-C</Option> (and we go for lots of coffee breaks).
</Para>

<Para>
The easiest way to see what <Option>-O</Option> (etc.) &ldquo;really mean&rdquo; is to run with
<Option>-v</Option>, then stand back in amazement.  Alternatively, just look at the
<Literal>HsC&lowbar;minus&lt;blah&gt;</Literal> lists in the GHC driver script.
</Para>

</Sect2>

<Sect2>
<Title><Option>-f*</Option>: platform-independent flags</Title>

<Para>
<IndexTerm><Primary>-f* options (GHC)</Primary></IndexTerm>
<IndexTerm><Primary>-fno-* options (GHC)</Primary></IndexTerm>
</Para>

<Para>
Flags can be turned <Emphasis>off</Emphasis> individually.  (NB: I hope you have a
good reason for doing this&hellip;) To turn off the <Option>-ffoo</Option> flag, just use
the <Option>-fno-foo</Option> flag.<IndexTerm><Primary>-fno-&lt;opt&gt; anti-option</Primary></IndexTerm> So, for
example, you can say <Option>-O2 -fno-strictness</Option>, which will then drop out
any running of the strictness analyser.
</Para>

<Para>
The options you are most likely to want to turn off are:

<ItemizedList>
<ListItem>

<Para>
<Option>-fno-strictness</Option><IndexTerm><Primary>-fno-strictness option</Primary></IndexTerm> (strictness
analyser, because it is sometimes slow),
</Para>
</ListItem>
<ListItem>

<Para>
<Option>-fno-specialise</Option><IndexTerm><Primary>-fno-specialise option</Primary></IndexTerm> (automatic
specialisation of overloaded functions, because it can make your code
bigger) (US spelling also accepted), and
</Para>
</ListItem>
<ListItem>

<Para>
<Option>-fno-cpr-analyse</Option><IndexTerm><Primary>-fno-cpr-analyse option</Primary></IndexTerm> switches off the CPR (constructed product
result) analyser.
</Para>
</ListItem>

</ItemizedList>

</Para>

<Para>
Should you wish to turn individual flags <Emphasis>on</Emphasis>, you are advised
to use the <Option>-Ofile</Option> option, described above.  Because the order in
which optimisation passes are run is sometimes crucial, it's quite
hard to do with command-line options.
</Para>

<Para>
Here are some &ldquo;dangerous&rdquo; optimisations you <Emphasis>might</Emphasis> want to try:
<VariableList>

<VarListEntry>
<Term><Option>-fvia-C</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-fvia-C option</Primary></IndexTerm>
<IndexTerm><Primary>native code generator, turning off</Primary></IndexTerm>
</Para>

<Para>
Compile via C, and don't use the native-code generator.  (There are many
cases when GHC does this on its own.) You might pick up a little bit of
speed by compiling via C (e.g. for floating-point intensive code on Intel).
If you use <Function>&lowbar;casm&lowbar;</Function>s (which are utterly
deprecated), you probably <Emphasis>have</Emphasis> to use
<Option>-fvia-C</Option>.
</Para>

<Para>
The lower-case incantation, <Option>-fvia-c</Option>, is synonymous.
</Para>

<Para>
Compiling via C will probably be slower (in compilation time) than
using GHC's native code generator.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-funfolding-interface-threshold&lt;n&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-funfolding-interface-threshold option</Primary></IndexTerm>
<IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
<IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
(Default: 30) By raising or lowering this number, you can raise or
lower the amount of pragmatic junk that gets spewed into interface
files.  (An unfolding has a &ldquo;size&rdquo; that reflects the cost in terms
of &ldquo;code bloat&rdquo; of expanding that unfolding in another module.  A
bigger function would be assigned a bigger cost.)
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-funfolding-creation-threshold&lt;n&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-funfolding-creation-threshold option</Primary></IndexTerm>
<IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
<IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
(Default: 30) This option is similar to
<Option>-funfolding-interface-threshold</Option>, except that it governs unfoldings
within a single module.  Increasing this figure is more likely to
result in longer compile times than faster code.  The next option is
more useful:
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-funfolding-use-threshold&lt;n&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-funfolding-use-threshold option</Primary></IndexTerm>
<IndexTerm><Primary>inlining, controlling</Primary></IndexTerm>
<IndexTerm><Primary>unfolding, controlling</Primary></IndexTerm>
(Default: 8) This is the magic cut-off figure for unfolding: below
this size, a function definition will be unfolded at the call-site,
any bigger and it won't.  The size computed for a function depends on
two things: the actual size of the expression minus any discounts that
apply (see <Option>-funfolding-con-discount</Option>).
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-funfolding-update-in-place&lt;n&gt;</Option>:</Term>
<ListItem>
<Para>
Switches on an experimental "optimisation".  Switching it on makes the compiler
a little keener to inline a function that returns a constructor, if the context is
that of a thunk.
<ProgramListing>
   x = plusInt a b
</ProgramListing>
If we inlined plusInt we might get an opportunity to use update-in-place for
the thunk 'x'.
</Para>
</ListItem>
</VarListEntry>

<VarListEntry>
<Term><Option>-funbox-strict-fields</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-funbox-strict-fields option</Primary></IndexTerm>
<IndexTerm><Primary>strict constructor fields</Primary></IndexTerm>
<IndexTerm><Primary>constructor fields, strict</Primary></IndexTerm>
</Para>

<Para>
This option causes all constructor fields which are marked strict
(i.e. &ldquo;!&rdquo;) to be unboxed or unpacked if possible.  For example:
</Para>

<Para>

<ProgramListing>
data T = T !Float !Float
</ProgramListing>

</Para>

<Para>
will create a constructor <Literal>T</Literal> containing two unboxed floats if the
<Option>-funbox-strict-fields</Option> flag is given.  This may not always be an
optimisation: if the <Function>T</Function> constructor is scrutinised and the floats
passed to a non-strict function for example, they will have to be
reboxed (this is done automatically by the compiler).
</Para>

<Para>
This option should only be used in conjunction with <Option>-O</Option>, in order to
expose unfoldings to the compiler so the reboxing can be removed as
often as possible.  For example:
</Para>

<Para>

<ProgramListing>
f :: T -&#62; Float
f (T f1 f2) = f1 + f2
</ProgramListing>

</Para>

<Para>
The compiler will avoid reboxing <Function>f1</Function> and <Function>f2</Function> by inlining <Function>+</Function> on
floats, but only when <Option>-O</Option> is on.
</Para>

<Para>
Any single-constructor data is eligible for unpacking; for example
</Para>

<Para>

<ProgramListing>
data T = T !(Int,Int)
</ProgramListing>

</Para>

<Para>
will store the two <Literal>Int</Literal>s directly in the <Function>T</Function> constructor, by flattening
the pair.  Multi-level unpacking is also supported:
</Para>

<Para>

<ProgramListing>
data T = T !S
data S = S !Int !Int
</ProgramListing>

</Para>

<Para>
will store two unboxed <Literal>Int&num;</Literal>s directly in the <Function>T</Function> constructor.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-fsemi-tagging</Option>:</Term>
<ListItem>
<Para>
This option (which <Emphasis>does not work</Emphasis> with the native-code generator)
tells the compiler to add extra code to test for already-evaluated
values.  You win if you have lots of such values during a run of your
program, you lose otherwise.  (And you pay in extra code space.)
</Para>

<Para>
We have not played with <Option>-fsemi-tagging</Option> enough to recommend it.
(For all we know, it doesn't even work anymore&hellip; Sigh.)
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-fexcess-precision</Option>:</Term>
<ListItem>
<Para>
When this option is given, intermediate floating point values can have
a <Emphasis>greater</Emphasis> precision/range than the final type.
Generally this is a good thing, but some programs may rely on the
exact precision/range of <Literal>Float</Literal>/<Literal>Double</Literal>
values and should not use this option for their compilation.
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

</Sect2>

<Sect2>
<Title><Option>-m*</Option>: platform-specific flags</Title>

<Para>
<IndexTerm><Primary>-m* options (GHC)</Primary></IndexTerm>
<IndexTerm><Primary>platform-specific options</Primary></IndexTerm>
<IndexTerm><Primary>machine-specific options</Primary></IndexTerm>
</Para>

<Para>
Some flags only make sense for particular target platforms.
</Para>

<Para>
<VariableList>

<VarListEntry>
<Term><Option>-mv8</Option>:</Term>
<ListItem>
<Para>
(SPARC machines)<IndexTerm><Primary>-mv8 option (SPARC only)</Primary></IndexTerm>
Means to pass the like-named option to GCC; it says to use the
Version 8 SPARC instructions, notably integer multiply and divide.
The similiar <Option>-m*</Option> GCC options for SPARC also work, actually.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-mlong-calls</Option>:</Term>
<ListItem>
<Para>
(HPPA machines)<IndexTerm><Primary>-mlong-calls option (HPPA only)</Primary></IndexTerm>
Means to pass the like-named option to GCC.  Required for Very Big
modules, maybe.  (Probably means you're in trouble&hellip;)
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-monly-[32]-regs</Option>:</Term>
<ListItem>
<Para>
(iX86 machines)<IndexTerm><Primary>-monly-N-regs option (iX86 only)</Primary></IndexTerm>
GHC tries to &ldquo;steal&rdquo; four registers from GCC, for performance
reasons; it almost always works.  However, when GCC is compiling some
modules with four stolen registers, it will crash, probably saying:

<Screen>
Foo.hc:533: fixed or forbidden register was spilled.
This may be due to a compiler bug or to impossible asm
statements or clauses.
</Screen>

Just give some registers back with <Option>-monly-N-regs</Option>.  Try `3' first,
then `2'.  If `2' doesn't work, please report the bug to us.
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

</Sect2>

<Sect2 id="optimise-C-compiler">
<Title>Code improvement by the C compiler.
</Title>

<Para>
<IndexTerm><Primary>optimisation by GCC</Primary></IndexTerm>
<IndexTerm><Primary>GCC optimisation</Primary></IndexTerm>
</Para>

<Para>
The C&nbsp;compiler (GCC) is run with <Option>-O</Option> turned on.  (It has
to be, actually).
</Para>

<Para>
If you want to run GCC with <Option>-O2</Option>&mdash;which may be worth a few
percent in execution speed&mdash;you can give a
<Option>-O2-for-C</Option><IndexTerm><Primary>-O2-for-C option</Primary></IndexTerm> option.
</Para>

</Sect2>

</Sect1>

<Sect1 id="options-phases">
<Title>Options related to a particular phase
</Title>

<Sect2 id="c-pre-processor">
<Title>The C pre-processor
</Title>

<Para>
<IndexTerm><Primary>pre-processing: cpp</Primary></IndexTerm>
<IndexTerm><Primary>C pre-processor options</Primary></IndexTerm>
<IndexTerm><Primary>cpp, pre-processing with</Primary></IndexTerm>
</Para>

<Para>
The C pre-processor <Command>cpp</Command> is run over your Haskell code only if the
<Option>-cpp</Option> option <IndexTerm><Primary>-cpp option</Primary></IndexTerm> is given.  Unless you are
building a large system with significant doses of conditional
compilation, you really shouldn't need it.
<VariableList>

<VarListEntry>
<Term><Option>-D&lt;foo&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-D&lt;name&gt; option</Primary></IndexTerm>
Define macro <Constant>&lt;foo&gt;</Constant> in the usual way.  NB: does <Emphasis>not</Emphasis> affect
<Option>-D</Option> macros passed to the C&nbsp;compiler when compiling via C!  For those,
use the <Option>-optc-Dfoo</Option> hack&hellip; (see <XRef LinkEnd="forcing-options-through">).
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-U&lt;foo&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-U&lt;name&gt; option</Primary></IndexTerm>
Undefine macro <Command>&lt;foo&gt;</Command> in the usual way.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-I&lt;dir&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-I&lt;dir&gt; option</Primary></IndexTerm>
Specify a directory in which to look for <Literal>&num;include</Literal> files, in
the usual C way.
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

<Para>
The GHC driver pre-defines several macros when processing Haskell
source code (<Filename>.hs</Filename> or <Filename>.lhs</Filename> files):
</Para>

<Para>
<VariableList>

<VarListEntry>
<Term><Constant>&lowbar;&lowbar;HASKELL98&lowbar;&lowbar;</Constant>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>&lowbar;&lowbar;HASKELL98&lowbar;&lowbar;</Primary></IndexTerm>
If defined, this means that GHC supports the language defined by the
Haskell 98 report.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Constant>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;=98</Constant>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;</Primary></IndexTerm>
In GHC 4.04 and later, the <Constant>&lowbar;&lowbar;HASKELL&lowbar;&lowbar;</Constant> macro is defined as having
the value <Constant>98</Constant>.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Constant>&lowbar;&lowbar;HASKELL1&lowbar;&lowbar;</Constant>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>&lowbar;&lowbar;HASKELL1&lowbar;&lowbar; macro</Primary></IndexTerm>
If defined to <Emphasis>n</Emphasis>, that means GHC supports the Haskell language
defined in the Haskell report version <Emphasis>1.n</Emphasis>.  Currently 5.  This
macro is deprecated, and will probably disappear in future versions.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Constant>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
For version <Emphasis>n</Emphasis> of the GHC system, this will be <Literal>&num;define</Literal>d to
<Emphasis>100n</Emphasis>.  So, for version 4.00, it is 400.
</Para>

<Para>
With any luck, <Constant>&lowbar;&lowbar;GLASGOW&lowbar;HASKELL&lowbar;&lowbar;</Constant> will be undefined in all other
implementations that support C-style pre-processing.
</Para>

<Para>
(For reference: the comparable symbols for other systems are:
<Constant>&lowbar;&lowbar;HUGS&lowbar;&lowbar;</Constant> for Hugs and <Constant>&lowbar;&lowbar;HBC&lowbar;&lowbar;</Constant> for Chalmers.)
</Para>

<Para>
NB. This macro is set when pre-processing both Haskell source and C
source, including the C source generated from a Haskell module
(i.e. <Filename>.hs</Filename>, <Filename>.lhs</Filename>, <Filename>.c</Filename> and <Filename>.hc</Filename> files).
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Constant>&lowbar;&lowbar;CONCURRENT&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>&lowbar;&lowbar;CONCURRENT&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
This symbol is defined when pre-processing Haskell (input) and
pre-processing C (GHC output).  Since GHC from verion 4.00 now
supports concurrent haskell by default, this symbol is always defined.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Constant>&lowbar;&lowbar;PARALLEL&lowbar;HASKELL&lowbar;&lowbar;</Constant>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>&lowbar;&lowbar;PARALLEL&lowbar;HASKELL&lowbar;&lowbar; macro</Primary></IndexTerm>
Only defined when <Option>-parallel</Option> is in use!  This symbol is defined when
pre-processing Haskell (input) and pre-processing C (GHC output).
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

<Para>
Options other than the above can be forced through to the C
pre-processor with the <Option>-opt</Option> flags (see
<XRef LinkEnd="forcing-options-through">).
</Para>

<Para>
A small word of warning: <Option>-cpp</Option> is not friendly to &ldquo;string
gaps&rdquo;.<IndexTerm><Primary>-cpp vs string gaps</Primary></IndexTerm><IndexTerm><Primary>string gaps vs
-cpp</Primary></IndexTerm>.  In other words, strings such as the following:
</Para>

<Para>

<ProgramListing>
strmod = "\
\ p \
\ "
</ProgramListing>

</Para>

<Para>
don't work with <Option>-cpp</Option>; <Filename>/usr/bin/cpp</Filename> elides the
backslash-newline pairs.
</Para>

<Para>
However, it appears that if you add a space at the end of the line,
then <Command>cpp</Command> (at least GNU <Command>cpp</Command> and possibly other <Command>cpp</Command>s)
leaves the backslash-space pairs alone and the string gap works as
expected.
</Para>

</Sect2>

<Sect2 id="options-C-compiler">
<Title>Options affecting the C compiler (if applicable)
</Title>

<Para>
<IndexTerm><Primary>include-file options</Primary></IndexTerm>
<IndexTerm><Primary>C compiler options</Primary></IndexTerm>
<IndexTerm><Primary>GCC options</Primary></IndexTerm>
</Para>

<Para>
At the moment, quite a few common C-compiler options are passed on
quietly to the C compilation of Haskell-compiler-generated C files.
THIS MAY CHANGE.  Meanwhile, options so sent are:
</Para>

<Para>

<InformalTable>
<TGroup Cols="2">
<ColSpec Align="Left" Colsep="0">
<ColSpec Align="Left" Colsep="0">
<TBody>
<Row>
<Entry><Option>-ansi</Option> </Entry>
<Entry> do ANSI C (not K&amp;R) </Entry>
</Row>
<Row>
<Entry>
<Option>-pedantic</Option> </Entry>
<Entry> be so</Entry>
</Row>
<Row>
<Entry>
<Option>-dgcc-lint</Option> </Entry>
<Entry> (hack) short for &ldquo;make GCC very paranoid&rdquo;</Entry>
</Row>

</TBody>

</TGroup>
</InformalTable>

<IndexTerm><Primary>-ansi option (for GCC)</Primary></IndexTerm>
<IndexTerm><Primary>-pedantic option (for GCC)</Primary></IndexTerm>
<IndexTerm><Primary>-dgcc-lint option (GCC paranoia)</Primary></IndexTerm>
</Para>

<Para>
If you are compiling with lots of foreign calls, you may need to
tell the C&nbsp;compiler about some <Literal>&num;include</Literal> files.  There is no real
pretty way to do this, but you can use this hack from the
command-line:
</Para>

<Para>

<Screen>
% ghc -c '-#include &#60;X/Xlib.h&#62;' Xstuff.lhs
</Screen>

</Para>

</Sect2>

<Sect2 id="options-linker">
<Title>Linking and consistency-checking
</Title>

<Para>
<IndexTerm><Primary>linker options</Primary></IndexTerm>
<IndexTerm><Primary>ld options</Primary></IndexTerm>
</Para>

<Para>
GHC has to link your code with various libraries, possibly including:
user-supplied, GHC-supplied, and system-supplied (<Option>-lm</Option> math
library, for example).
</Para>

<Para>
<VariableList>

<VarListEntry>
<Term><Option>-l&lt;FOO&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-l&lt;lib&gt; option</Primary></IndexTerm>
Link in a library named <Filename>lib&lt;FOO&gt;.a</Filename> which resides somewhere on the
library directories path.
</Para>

<Para>
Because of the sad state of most UNIX linkers, the order of such
options does matter.  Thus: <Command>ghc -lbar *.o</Command> is almost certainly
wrong, because it will search <Filename>libbar.a</Filename> <Emphasis>before</Emphasis> it has
collected unresolved symbols from the <Filename>*.o</Filename> files.
<Command>ghc *.o -lbar</Command> is probably better.
</Para>

<Para>
The linker will of course be informed about some GHC-supplied
libraries automatically; these are:
</Para>

<Para>

<InformalTable>
<TGroup Cols="2">
<ColSpec Align="Left" Colsep="0">
<ColSpec Align="Left" Colsep="0">
<TBody>
<Row>
<Entry><Emphasis>-l equivalent</Emphasis> </Entry>
<Entry> <Emphasis>description</Emphasis> </Entry>
</Row>

<Row>
<Entry>
<Option>-lHSrts,-lHSclib</Option> </Entry>
<Entry> basic runtime libraries </Entry>
</Row>
<Row>
<Entry>
<Option>-lHS</Option> </Entry>
<Entry> standard Prelude library </Entry>
</Row>
<Row>
<Entry>
<Option>-lHS&lowbar;cbits</Option> </Entry>
<Entry> C support code for standard Prelude library </Entry>
</Row>
<Row>
<Entry>
<Option>-lgmp</Option> </Entry>
<Entry> GNU multi-precision library (for Integers)</Entry>
</Row>

</TBody>

</TGroup>
</InformalTable>

</Para>

<Para>
<IndexTerm><Primary>-lHS library</Primary></IndexTerm>
<IndexTerm><Primary>-lHS&lowbar;cbits library</Primary></IndexTerm>
<IndexTerm><Primary>-lHSrts library</Primary></IndexTerm>
<IndexTerm><Primary>-lgmp library</Primary></IndexTerm>
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-package &lt;name&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-package &lt;name&gt; option</Primary></IndexTerm>
</Para>

<Para>
If you are using a Haskell &ldquo;package&rdquo; (e.g., the POSIX
library), just use the <Option>-package posix</Option> option, and the
correct code should be linked in.  See <xref linkend="packages"> for
more details.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-L&lt;dir&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-L&lt;dir&gt; option</Primary></IndexTerm>
Where to find user-supplied libraries&hellip;  Prepend the directory
<Filename>&lt;dir&gt;</Filename> to the library directories path.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-static</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-static option</Primary></IndexTerm>
Tell the linker to avoid shared libraries.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-no-link-chk</Option> and <Option>-link-chk</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-no-link-chk option</Primary></IndexTerm>
<IndexTerm><Primary>-link-chk option</Primary></IndexTerm>
<IndexTerm><Primary>consistency checking of executables</Primary></IndexTerm>
By default, immediately after linking an executable, GHC verifies that
the pieces that went into it were compiled with compatible flags; a
&ldquo;consistency check&rdquo;.
(This is to avoid mysterious failures caused by non-meshing of
incompatibly-compiled programs; e.g., if one <Filename>.o</Filename> file was compiled
for a parallel machine and the others weren't.)  You may turn off this
check with <Option>-no-link-chk</Option>.  You can turn it (back) on with
<Option>-link-chk</Option> (the default).
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-no-hs-main</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-no-hs-main option</Primary></IndexTerm>
<IndexTerm><Primary>linking Haskell libraries with foreign code</Primary></IndexTerm>
</Para>

<Para>
In the event you want to include ghc-compiled code as part of another
(non-Haskell) program, the RTS will not be supplying its definition of
<Function>main()</Function> at link-time, you will have to. To signal that to the
driver script when linking, use <Option>-no-hs-main</Option>.
</Para>

<Para>
Notice that since the command-line passed to the linker is rather
involved, you probably want to use the ghc driver script to do the
final link of your `mixed-language' application. This is not a
requirement though, just try linking once with <Option>-v</Option> on to see what
options the driver passes through to the linker.
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

</Sect2>

</Sect1>

<Sect1 id="sec-using-concurrent">
<Title>Using Concurrent Haskell</Title>

<Para>
<IndexTerm><Primary>Concurrent Haskell&mdash;use</Primary></IndexTerm>
</Para>

<Para>
GHC (as of version 4.00) supports Concurrent Haskell by default,
without requiring a special option or libraries compiled in a certain
way.  To get access to the support libraries for Concurrent Haskell
(i.e. <Literal>Concurrent</Literal> and friends), use the
<Option>-package concurrent</Option> option.
</Para>

<Para>
Three RTS options are provided for modifying the behaviour of the
threaded runtime system.  See the descriptions of
<Option>-C[&lt;us&gt;]</Option>, <Option>-q</Option>, and
<Option>-t&lt;num&gt;</Option> in <XRef LinkEnd="parallel-rts-opts">.
</Para>

<Para>
Concurrent Haskell is described in more detail in <XRef
LinkEnd="sec-Concurrent">.
</Para>

</Sect1>

<Sect1 id="sec-using-parallel">
<Title>Using Parallel Haskell</Title>

<Para>
<IndexTerm><Primary>Parallel Haskell&mdash;use</Primary></IndexTerm>
</Para>

<Para>
&lsqb;You won't be able to execute parallel Haskell programs unless PVM3
(Parallel Virtual Machine, version 3) is installed at your site.]
</Para>

<Para>
To compile a Haskell program for parallel execution under PVM, use the
<Option>-parallel</Option> option,<IndexTerm><Primary>-parallel
option</Primary></IndexTerm> both when compiling <Emphasis>and
linking</Emphasis>.  You will probably want to <Literal>import
Parallel</Literal> into your Haskell modules.
</Para>

<Para>
To run your parallel program, once PVM is going, just invoke it
&ldquo;as normal&rdquo;.  The main extra RTS option is
<Option>-N&lt;n&gt;</Option>, to say how many PVM
&ldquo;processors&rdquo; your program to run on.  (For more details of
all relevant RTS options, please see <XRef
LinkEnd="parallel-rts-opts">.)
</Para>

<Para>
In truth, running Parallel Haskell programs and getting information
out of them (e.g., parallelism profiles) is a battle with the vagaries of
PVM, detailed in the following sections.
</Para>

<Sect2>
<Title>Dummy's guide to using PVM</Title>

<Para>
<IndexTerm><Primary>PVM, how to use</Primary></IndexTerm>
<IndexTerm><Primary>Parallel Haskell&mdash;PVM use</Primary></IndexTerm>
Before you can run a parallel program under PVM, you must set the
required environment variables (PVM's idea, not ours); something like,
probably in your <Filename>.cshrc</Filename> or equivalent:

<ProgramListing>
setenv PVM_ROOT /wherever/you/put/it
setenv PVM_ARCH `$PVM_ROOT/lib/pvmgetarch`
setenv PVM_DPATH $PVM_ROOT/lib/pvmd
</ProgramListing>

</Para>

<Para>
Creating and/or controlling your &ldquo;parallel machine&rdquo; is a purely-PVM
business; nothing specific to Parallel Haskell.
</Para>

<Para>
You use the <Command>pvm</Command><IndexTerm><Primary>pvm command</Primary></IndexTerm> command to start PVM on your
machine.  You can then do various things to control/monitor your
&ldquo;parallel machine;&rdquo; the most useful being:
</Para>

<Para>
<InformalTable>
<TGroup Cols=2>
<ColSpec Align="Left">
<TBody>

<Row>
<Entry><KeyCombo><KeyCap>Control</KeyCap><KeyCap>D</KeyCap></KeyCombo></Entry>
<Entry>exit <Command>pvm</Command>, leaving it running</Entry>
</Row>

<Row>
<Entry><Command>halt</Command></Entry>
<Entry>kill off this &ldquo;parallel machine&rdquo; &amp; exit</Entry>
</Row>

<Row>
<Entry><Command>add &lt;host&gt;</Command></Entry>
<Entry>add <Command>&lt;host&gt;</Command> as a processor</Entry>
</Row>

<Row>
<Entry><Command>delete &lt;host&gt;</Command></Entry>
<Entry>delete <Command>&lt;host&gt;</Command></Entry>
</Row>

<Row>
<Entry><Command>reset</Command></Entry>
<Entry>kill what's going, but leave PVM up</Entry>
</Row>

<Row>
<Entry><Command>conf</Command></Entry>
<Entry>list the current configuration</Entry>
</Row>

<Row>
<Entry><Command>ps</Command></Entry>
<Entry>report processes' status</Entry>
</Row>

<Row>
<Entry><Command>pstat &lt;pid&gt;</Command></Entry>
<Entry>status of a particular process</Entry>
</Row>

</TBody>
</TGroup>
</InformalTable>
</Para>

<Para>
The PVM documentation can tell you much, much more about <Command>pvm</Command>!
</Para>

</Sect2>

<Sect2>
<Title>Parallelism profiles</Title>

<Para>
<IndexTerm><Primary>parallelism profiles</Primary></IndexTerm>
<IndexTerm><Primary>profiles, parallelism</Primary></IndexTerm>
<IndexTerm><Primary>visualisation tools</Primary></IndexTerm>
</Para>

<Para>
With Parallel Haskell programs, we usually don't care about the
results&mdash;only with &ldquo;how parallel&rdquo; it was!  We want pretty pictures.
</Para>

<Para>
Parallelism profiles (&agrave; la <Command>hbcpp</Command>) can be generated with the
<Option>-q</Option><IndexTerm><Primary>-q RTS option (concurrent, parallel)</Primary></IndexTerm> RTS option.  The
per-processor profiling info is dumped into files named
<Filename>&lt;full-path&gt;&lt;program&gt;.gr</Filename>.  These are then munged into a PostScript picture,
which you can then display.  For example, to run your program
<Filename>a.out</Filename> on 8 processors, then view the parallelism profile, do:
</Para>

<Para>

<Screen>
% ./a.out +RTS -N8 -q
% grs2gr *.???.gr &#62; temp.gr     # combine the 8 .gr files into one
% gr2ps -O temp.gr              # cvt to .ps; output in temp.ps
% ghostview -seascape temp.ps   # look at it!
</Screen>

</Para>

<Para>
The scripts for processing the parallelism profiles are distributed
in <Filename>ghc/utils/parallel/</Filename>.
</Para>

</Sect2>

<Sect2>
<Title>Other useful info about running parallel programs</Title>

<Para>
The &ldquo;garbage-collection statistics&rdquo; RTS options can be useful for
seeing what parallel programs are doing.  If you do either
<Option>+RTS -Sstderr</Option><IndexTerm><Primary>-Sstderr RTS option</Primary></IndexTerm> or <Option>+RTS -sstderr</Option>, then
you'll get mutator, garbage-collection, etc., times on standard
error. The standard error of all PE's other than the `main thread'
appears in <Filename>/tmp/pvml.nnn</Filename>, courtesy of PVM.
</Para>

<Para>
Whether doing <Option>+RTS -Sstderr</Option> or not, a handy way to watch
what's happening overall is: <Command>tail -f /tmp/pvml.nnn</Command>.
</Para>

</Sect2>

<Sect2 id="parallel-rts-opts">
<Title>RTS options for Concurrent/Parallel Haskell
</Title>

<Para>
<IndexTerm><Primary>RTS options, concurrent</Primary></IndexTerm>
<IndexTerm><Primary>RTS options, parallel</Primary></IndexTerm>
<IndexTerm><Primary>Concurrent Haskell&mdash;RTS options</Primary></IndexTerm>
<IndexTerm><Primary>Parallel Haskell&mdash;RTS options</Primary></IndexTerm>
</Para>

<Para>
Besides the usual runtime system (RTS) options
(<XRef LinkEnd="runtime-control">), there are a few options particularly
for concurrent/parallel execution.
</Para>

<Para>
<VariableList>

<VarListEntry>
<Term><Option>-N&lt;N&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-N&lt;N&gt; RTS option (parallel)</Primary></IndexTerm>
(PARALLEL ONLY) Use <Literal>&lt;N&gt;</Literal> PVM processors to run this program;
the default is 2.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-C[&lt;us&gt;]</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-C&lt;us&gt; RTS option</Primary></IndexTerm> Sets
the context switch interval to <Literal>&lt;s&gt;</Literal> seconds.
A context switch will occur at the next heap block allocation after
the timer expires (a heap block allocation occurs every 4k of
allocation).  With <Option>-C0</Option> or <Option>-C</Option>,
context switches will occur as often as possible (at every heap block
allocation).  By default, context switches occur every 20ms
milliseconds.  Note that GHC's internal timer ticks every 20ms, and
the context switch timer is always a multiple of this timer, so 20ms
is the maximum granularity available for timed context switches.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-q[v]</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-q RTS option</Primary></IndexTerm>
(PARALLEL ONLY) Produce a quasi-parallel profile of thread activity,
in the file <FIlename>&lt;program&gt;.qp</FIlename>.  In the style of <Command>hbcpp</Command>, this profile
records the movement of threads between the green (runnable) and red
(blocked) queues.  If you specify the verbose suboption (<Option>-qv</Option>), the
green queue is split into green (for the currently running thread
only) and amber (for other runnable threads).  We do not recommend
that you use the verbose suboption if you are planning to use the
<Command>hbcpp</Command> profiling tools or if you are context switching at every heap
check (with <Option>-C</Option>).
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-t&lt;num&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-t&lt;num&gt; RTS option</Primary></IndexTerm>
(PARALLEL ONLY) Limit the number of concurrent threads per processor
to <Literal>&lt;num&gt;</Literal>.  The default is 32.  Each thread requires slightly over 1K
<Emphasis>words</Emphasis> in the heap for thread state and stack objects.  (For
32-bit machines, this translates to 4K bytes, and for 64-bit machines,
8K bytes.)
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-d</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-d RTS option (parallel)</Primary></IndexTerm>
(PARALLEL ONLY) Turn on debugging.  It pops up one xterm (or GDB, or
something&hellip;) per PVM processor.  We use the standard <Command>debugger</Command>
script that comes with PVM3, but we sometimes meddle with the
<Command>debugger2</Command> script.  We include ours in the GHC distribution,
in <Filename>ghc/utils/pvm/</Filename>.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-e&lt;num&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-e&lt;num&gt; RTS option (parallel)</Primary></IndexTerm>
(PARALLEL ONLY) Limit the number of pending sparks per processor to
<Literal>&lt;num&gt;</Literal>. The default is 100. A larger number may be appropriate if
your program generates large amounts of parallelism initially.
</Para>
</ListItem>
</VarListEntry>
<VarListEntry>
<Term><Option>-Q&lt;num&gt;</Option>:</Term>
<ListItem>
<Para>
<IndexTerm><Primary>-Q&lt;num&gt; RTS option (parallel)</Primary></IndexTerm>
(PARALLEL ONLY) Set the size of packets transmitted between processors
to <Literal>&lt;num&gt;</Literal>. The default is 1024 words. A larger number may be
appropriate if your machine has a high communication cost relative to
computation speed.
</Para>
</ListItem>
</VarListEntry>
</VariableList>
</Para>

</Sect2>

</Sect1>

&runtime
&debug

</Chapter>

<!-- Emacs stuff:
     ;;; Local Variables: ***
     ;;; mode: sgml ***
     ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter") ***
     ;;; End: ***
 -->