1 Getting started with hacking on GHC
2 -----------------------------------
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.
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.
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.
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).
28 A good mk/build.mk to start hacking on GHC is:
31 SRC_HC_OPTS = -H32m -O -fasm -Rghc-timing
32 GhcStage1HcOpts = -O0 -DDEBUG
33 GhcLibHcOpts = -O -fgenerics
38 What do these options do?
40 SRC_HC_OPTS = -H32m -O -fasm -Rghc-timing
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
48 GhcStage1HcOpts = -O0 -DDEBUG
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.
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.
62 GhcLibHcOpts = -O -fgenerics
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.
73 Normally the profiled libs are built. Setting GhcLibWays to
74 empty disables this, so you only build the normal libs.
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.
84 Actually building the bits
85 --------------------------
87 To just build everything, from the top level:
95 Building individual parts of the tree
96 -------------------------------------
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 ghc/utils/genprimopcode is built as part of 'make boot', because it is
102 required to preprocess ghc/compiler/prelude/primops.txt.pp.
104 After 'make boot', 'make' will build everything.
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.
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.
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.
127 GhcStage2HcOpts = -O0 -DDEBUG
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).
137 To turn up everything to the max, for running performance tests for
140 SRC_HC_OPTS = -H64m -O2
144 You can even add some more aggresive options, such as
145 -fliberate-case-threshold50, -funfolding-use-threshold50.
151 A rough roadmap to the source tree:
153 distrib materials for building distributions
155 docs build system documentation
158 rts the runtime system and storage manager
159 lib libraries used in GHC and its tools
160 utils tools that come with GHC, and tools used in the build
161 compiler the compiler itself
162 driver various scripts, and package databases
163 docs compiler documentation
164 includes header files shipped with GHC
166 glafp-utils tools for the build system
168 libraries The hierarchical libraries
170 nofib A benchmark suite
172 testsuite The regression test suite
178 The GHC Developer's Wiki
180 The home for GHC Developers, with information on accessing the latest sources,
181 the bug tracker, and further documentation on the code.
182 http://hackage.haskell.org/trac/ghc
187 Full documentation on the build system.
188 http://www.haskell.org/ghc/docs/latest/html/building/index.html
193 Notes on the internals and architecture of GHC. Much of this isn't
194 up to date, but there is still lots of useful stuff in there. Read
195 in conjunction with the source code.
196 http://www.cse.unsw.edu.au/~chak/haskell/ghc/comm/
201 Ask on glasgow-haskell-users@haskell.org if you have difficulties.
202 If you're working with the current CVS sources of GHC, then
203 cvs-ghc@haskell.org might be a more appropriate (developers hang
204 out here). See http://www.haskell.org/mailman/listinfo for
208 Happy Hacking! --The GHC Team