[project @ 2005-10-25 09:35:57 by simonmar]
[ghc-hetmet.git] / ghc / HACKING
1 Getting started with hacking on GHC
2 -----------------------------------
3
4 So you've decided to hack on GHC, congratulations!  We hope you have a
5 rewarding experience.  This file contains a few nuggets of information
6 that will help get you started right away, and point you in the
7 direction of more comprehensive documentation for later.
8
9
10 Setting up your build
11 ---------------------
12
13 The GHC build tree is set up so that, by default, it builds a compiler
14 ready for installing and using.  That means full optimisation, and the
15 build can take a *long* time.  If you unpack your source tree and
16 right away say "./configure; make", expect to have to wait a while.
17
18 For hacking, you want the build to be quick - quick to build in the
19 first place, and quick to rebuild after making changes.  Tuning your
20 build setup can make the difference between several hours to build
21 GHC, and less than an hour.  Here's how to do it.
22
23 mk/build.mk is a GNU makefile that contains all your build settings.
24 By default, this file doesn't exist, and all the parameters are set to
25 their defaults in mk/config.mk (mk/config.mk is the place to look for
26 *all* the things you might want to tune).
27
28 A good mk/build.mk to start hacking on GHC is:
29
30 ------
31 SRC_HC_OPTS     = -H32m -O -fasm -Rghc-timing
32 GhcStage1HcOpts = -O0 -DDEBUG
33 GhcLibHcOpts    = -O -fgenerics
34 GhcLibWays      =
35 SplitObjs       = NO
36 ------
37
38 What do these options do?
39
40 SRC_HC_OPTS = -H32m -O -fasm -Rghc-timing
41
42   These options are added to the command line for all Haskell
43   compilations.  We turn on -fasm, because that halves compilation
44   time at the expense of a few percent performance.  -Rghc-timing
45   prints out a line of timing info about each compilation.  It's handy
46   to keep an eye on.
47
48 GhcStage1HcOpts = -O0 -DDEBUG
49
50   The options for building the stage1 compiler (these come after
51   SRC_HC_OPTS, so you can override settings from there).  We turn off
52   optimisation here, assuming you'll be modifying and testing stage1.
53   With optimisation off, rebuilding GHC after modifying it will be
54   *much* quicker, not only because the individual compilations will be
55   quicker, but also there will be fewer dependencies between modules,
56   so less stuff needs to be rebuilt after each modification.
57
58   Also we turn on -DDEBUG, because that enables assertions and
59   debugging code in the compiler itself.  Turning on DEBUG makes
60   the compiler about 30% slower.
61
62 GhcLibHcOpts = -O -fgenerics
63
64   You almost certainly want optimisation *on* when building
65   libraries, otherwise the code you build with this compiler
66   goes really slowly.  -fgenerics add generics support to the
67   libraries - you can turn this off if you like (it'll make the
68   libraries a bit smaller), but you won't be able to use Generics in
69   the code you build against these libraries.
70
71 GhcLibWays =
72
73   Normally the profiled libs are built.  Setting GhcLibWays to
74   empty disables this, so you only build the normal libs.
75
76 SplitObjs = NO
77
78   Object splitting causes each module to be split into smaller
79   pieces in the final library, to reduce executable sizes when
80   linking against the library.  It can be quite time and
81   memory-consuming, so turn it off when you're hacking.
82
83
84 Refining the setup
85 ------------------
86
87 If you will be hacking mostly on libraries, then you probably want to
88 build stage1 with optimisation, because you're only building it once
89 but using it many times.
90
91   GhcState1HcOpts = -O
92
93 If you are working on GHCi or Template Haskell, then you will be
94 building and modifying the stage 2 compiler.  Hence, you want to build
95 stage 1 with, and stage 2 without, optimisation.
96
97   GhcState1HcOpts = -O
98   GhcState2HcOpts = -O0 -DDEBUG
99
100 Take a look through mk/config.mk for more settings you might want to
101 override in build.mk.  Remember: don't modify config.mk directly (it
102 gets overwritten when you run ./configure).
103
104
105 Full optimisation
106 -----------------
107
108 To turn up everything to the max, for running performance tests for
109 example, try theses:
110
111   SRC_HC_OPTS  = -H64m -O2 
112   GhcLibHcOpts = -O2
113   SplitObjs    = YES
114
115 You can even add some more aggresive options, such as
116 -fliberate-case-threshold50, -funfolding-use-threshold50.
117
118
119 Roadmap
120 -------
121
122 A rough roadmap to the source tree:
123
124  distrib        materials for building distributions
125
126  docs           build system documentation
127
128  ghc            The GHC Compiler
129    rts          the runtime system and storage manager
130    lib          libraries used in GHC and its tools
131    utils        tools that come with GHC, and tools used in the build
132    compiler     the compiler itself
133    driver       various scripts, and package databases
134    docs         compiler documentation
135    includes     header files shipped with GHC
136
137  glafp-utils    tools for the build system
138
139  libraries      The hierarchical libraries
140
141  nofib          A benchmark suite
142
143  testsuite      The regression test suite
144
145
146 Resources
147 ---------
148
149 The Building Guide
150
151    Full documentation on the build system.
152    http://www.haskell.org/ghc/docs/latest/html/building/index.html
153
154
155 The GHC Commentary
156
157    Notes on the internals and architecture of GHC.  Much of this isn't
158    up to date, but there is still lots of useful stuff in there.  Read
159    in conjunction with the source code.
160    http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/
161
162
163 Mailing lists
164
165    Ask on glasgow-haskell-users@haskell.org if you have difficulties.
166    If you're working with the current CVS sources of GHC, then
167    cvs-ghc@haskell.org might be a more appropriate (developers hang
168    out here).  See http://www.haskell.org/mailman/listinfo for
169    subscription.
170
171
172 Happy Hacking!  --The GHC Team