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.
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.
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.
98 GhcState2HcOpts = -O0 -DDEBUG
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).
108 To turn up everything to the max, for running performance tests for
111 SRC_HC_OPTS = -H64m -O2
115 You can even add some more aggresive options, such as
116 -fliberate-case-threshold50, -funfolding-use-threshold50.
122 A rough roadmap to the source tree:
124 distrib materials for building distributions
126 docs build system documentation
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
137 glafp-utils tools for the build system
139 libraries The hierarchical libraries
141 nofib A benchmark suite
143 testsuite The regression test suite
151 Full documentation on the build system.
152 http://www.haskell.org/ghc/docs/latest/html/building/index.html
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/
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
172 Happy Hacking! --The GHC Team