Add a new section "Getting the Source" to both HACKING and README. But what about...
[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 Getting the sources
11 -------------------
12
13 First get the GHC darcs repository:
14
15    $ darcs get http://darcs.haskell.org/ghc/
16
17 Then run the darcs-all shell script in that repository 
18 to get the other repositories:
19
20    $ cd ghc
21    $ sh darcs-all
22
23
24 Setting up your build
25 ---------------------
26
27 The GHC build tree is set up so that, by default, it builds a compiler
28 ready for installing and using.  That means full optimisation, and the
29 build can take a *long* time.  If you unpack your source tree and
30 right away say "./configure; make", expect to have to wait a while.
31
32 For hacking, you want the build to be quick - quick to build in the
33 first place, and quick to rebuild after making changes.  Tuning your
34 build setup can make the difference between several hours to build
35 GHC, and less than an hour.  Here's how to do it.
36
37 mk/build.mk is a GNU makefile that contains all your build settings.
38 By default, this file doesn't exist, and all the parameters are set to
39 their defaults in mk/config.mk (mk/config.mk is the place to look for
40 *all* the things you might want to tune).
41
42 A good mk/build.mk to start hacking on GHC is:
43
44 ------
45 SRC_HC_OPTS     = -H32m -O -fasm -Rghc-timing
46 GhcStage1HcOpts = -O0 -DDEBUG
47 GhcLibHcOpts    = -O -fgenerics
48 GhcLibWays      =
49 SplitObjs       = NO
50 ------
51
52 What do these options do?
53
54 SRC_HC_OPTS = -H32m -O -fasm -Rghc-timing
55
56   These options are added to the command line for all Haskell
57   compilations.  We turn on -fasm, because that halves compilation
58   time at the expense of a few percent performance.  -Rghc-timing
59   prints out a line of timing info about each compilation.  It's handy
60   to keep an eye on.
61
62 GhcStage1HcOpts = -O0 -DDEBUG
63
64   The options for building the stage1 compiler (these come after
65   SRC_HC_OPTS, so you can override settings from there).  We turn off
66   optimisation here, assuming you'll be modifying and testing stage1.
67   With optimisation off, rebuilding GHC after modifying it will be
68   *much* quicker, not only because the individual compilations will be
69   quicker, but also there will be fewer dependencies between modules,
70   so less stuff needs to be rebuilt after each modification.
71
72   Also we turn on -DDEBUG, because that enables assertions and
73   debugging code in the compiler itself.  Turning on DEBUG makes
74   the compiler about 30% slower.
75
76 GhcLibHcOpts = -O -fgenerics
77
78   You almost certainly want optimisation *on* when building
79   libraries, otherwise the code you build with this compiler
80   goes really slowly.  -fgenerics add generics support to the
81   libraries - you can turn this off if you like (it'll make the
82   libraries a bit smaller), but you won't be able to use Generics in
83   the code you build against these libraries.
84
85 GhcLibWays =
86
87   Normally the profiled libs are built.  Setting GhcLibWays to
88   empty disables this, so you only build the normal libs.
89
90 SplitObjs = NO
91
92   Object splitting causes each module to be split into smaller
93   pieces in the final library, to reduce executable sizes when
94   linking against the library.  It can be quite time and
95   memory-consuming, so turn it off when you're hacking.
96
97
98 Actually building the bits
99 --------------------------
100
101 To just build everything, from the top level:
102
103   $ autoreconf
104   $ ./configure
105   $ make
106   $ make install
107
108
109 Building individual parts of the tree
110 -------------------------------------
111
112 The first thing to understand is that the source tree is built in two
113 passes.  First 'make boot' builds dependencies and any other tools
114 required as part of the build itself.  For example,
115 utils/genprimopcode is built as part of 'make boot', because it is
116 required to preprocess compiler/prelude/primops.txt.pp.
117
118 After 'make boot', 'make' will build everything.
119
120 If you say 'make' from the very top-level, the build system will
121 arrange to do the appropriate 'make boot' steps for you.  If you just
122 want to build in a subdirectory (eg. ghc), you have to do 'make boot'
123 yourself.  You don't need to 'make boot' after every single change,
124 but you might want to do it to update dependencies, for example.
125
126
127 Refining the setup
128 ------------------
129
130 If you will be hacking mostly on libraries, then you probably want to
131 build stage1 with optimisation, because you're only building it once
132 but using it many times.
133
134   GhcStage1HcOpts = -O
135
136 If you are working on GHCi or Template Haskell, then you will be
137 building and modifying the stage 2 compiler.  Hence, you want to build
138 stage 1 with, and stage 2 without, optimisation.
139
140   GhcStage1HcOpts = -O
141   GhcStage2HcOpts = -O0 -DDEBUG
142
143 Take a look through mk/config.mk for more settings you might want to
144 override in build.mk.  Remember: don't modify config.mk directly (it
145 gets overwritten when you run ./configure).
146
147
148 Full optimisation
149 -----------------
150
151 To turn up everything to the max, for running performance tests for
152 example, try theses:
153
154   SRC_HC_OPTS  = -H64m -O2 
155   GhcLibHcOpts = -O2
156   SplitObjs    = YES
157
158 You can even add some more aggresive options, such as
159 -fliberate-case-threshold50, -funfolding-use-threshold50.
160
161
162 Roadmap
163 -------
164
165 A rough roadmap to the source tree:
166
167  compat         compatibility library used by GHC and utils
168  compiler       the compiler itself
169  distrib        materials for building distributions
170  driver         various scripts, and package databases
171  docs           all documentation
172  includes       header files shipped with GHC
173  libraries      The hierarchical libraries
174  nofib          A benchmark suite (optional)
175  rts            the runtime system and storage manager
176  testsuite      The regression test suite (optional)
177  utils          tools that come with GHC, and tools used in the build
178
179 Resources
180 ---------
181
182 The GHC Developer's Wiki
183
184    The home for GHC Developers, with information on accessing the latest sources,
185    the bug tracker, and further documentation on the code.
186    http://hackage.haskell.org/trac/ghc
187
188
189 The Building Guide
190
191    Full documentation on the build system.
192    http://www.haskell.org/ghc/docs/latest/html/building/index.html
193
194
195 The GHC Commentary
196
197    Notes on the internals and architecture of GHC.  Much of this isn't
198    up to date, but there is still lots of useful stuff in there.  Read
199    in conjunction with the source code.
200    http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/
201
202
203 Mailing lists
204
205    Ask on glasgow-haskell-users@haskell.org if you have difficulties.
206    If you're working with the current CVS sources of GHC, then
207    cvs-ghc@haskell.org might be a more appropriate (developers hang
208    out here).  See http://www.haskell.org/mailman/listinfo for
209    subscription.
210
211
212 Happy Hacking!  --The GHC Team