update for new source tree layout
[ghc-hetmet.git] / 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 Actually building the bits
85 --------------------------
86
87 To just build everything, from the top level:
88
89   $ autoreconf
90   $ ./configure
91   $ make
92   $ make install
93
94
95 Building individual parts of the tree
96 -------------------------------------
97
98 The first thing to understand is that the source tree is built in two
99 passes.  First 'make boot' builds dependencies and any other tools
100 required as part of the build itself.  For example,
101 utils/genprimopcode is built as part of 'make boot', because it is
102 required to preprocess compiler/prelude/primops.txt.pp.
103
104 After 'make boot', 'make' will build everything.
105
106 If you say 'make' from the very top-level, the build system will
107 arrange to do the appropriate 'make boot' steps for you.  If you just
108 want to build in a subdirectory (eg. ghc), you have to do 'make boot'
109 yourself.  You don't need to 'make boot' after every single change,
110 but you might want to do it to update dependencies, for example.
111
112
113 Refining the setup
114 ------------------
115
116 If you will be hacking mostly on libraries, then you probably want to
117 build stage1 with optimisation, because you're only building it once
118 but using it many times.
119
120   GhcStage1HcOpts = -O
121
122 If you are working on GHCi or Template Haskell, then you will be
123 building and modifying the stage 2 compiler.  Hence, you want to build
124 stage 1 with, and stage 2 without, optimisation.
125
126   GhcStage1HcOpts = -O
127   GhcStage2HcOpts = -O0 -DDEBUG
128
129 Take a look through mk/config.mk for more settings you might want to
130 override in build.mk.  Remember: don't modify config.mk directly (it
131 gets overwritten when you run ./configure).
132
133
134 Full optimisation
135 -----------------
136
137 To turn up everything to the max, for running performance tests for
138 example, try theses:
139
140   SRC_HC_OPTS  = -H64m -O2 
141   GhcLibHcOpts = -O2
142   SplitObjs    = YES
143
144 You can even add some more aggresive options, such as
145 -fliberate-case-threshold50, -funfolding-use-threshold50.
146
147
148 Roadmap
149 -------
150
151 A rough roadmap to the source tree:
152
153  compat         compatibility library used by GHC and utils
154  compiler       the compiler itself
155  distrib        materials for building distributions
156  driver         various scripts, and package databases
157  docs           all documentation
158  includes       header files shipped with GHC
159  libraries      The hierarchical libraries
160  nofib          A benchmark suite (optional)
161  rts            the runtime system and storage manager
162  testsuite      The regression test suite (optional)
163  utils          tools that come with GHC, and tools used in the build
164
165 Resources
166 ---------
167
168 The GHC Developer's Wiki
169
170    The home for GHC Developers, with information on accessing the latest sources,
171    the bug tracker, and further documentation on the code.
172    http://hackage.haskell.org/trac/ghc
173
174
175 The Building Guide
176
177    Full documentation on the build system.
178    http://www.haskell.org/ghc/docs/latest/html/building/index.html
179
180
181 The GHC Commentary
182
183    Notes on the internals and architecture of GHC.  Much of this isn't
184    up to date, but there is still lots of useful stuff in there.  Read
185    in conjunction with the source code.
186    http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/
187
188
189 Mailing lists
190
191    Ask on glasgow-haskell-users@haskell.org if you have difficulties.
192    If you're working with the current CVS sources of GHC, then
193    cvs-ghc@haskell.org might be a more appropriate (developers hang
194    out here).  See http://www.haskell.org/mailman/listinfo for
195    subscription.
196
197
198 Happy Hacking!  --The GHC Team