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 First get the GHC darcs repository:
15 $ darcs get http://darcs.haskell.org/ghc/
17 Then run the darcs-all shell script in that repository
18 to get the other repositories:
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.
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.
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).
42 A good mk/build.mk to start hacking on GHC is:
45 SRC_HC_OPTS = -H32m -O -fasm -Rghc-timing
46 GhcStage1HcOpts = -O0 -DDEBUG
47 GhcLibHcOpts = -O -fgenerics
52 What do these options do?
54 SRC_HC_OPTS = -H32m -O -fasm -Rghc-timing
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
62 GhcStage1HcOpts = -O0 -DDEBUG
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.
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.
76 GhcLibHcOpts = -O -fgenerics
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.
87 Normally the profiled libs are built. Setting GhcLibWays to
88 empty disables this, so you only build the normal libs.
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.
98 Actually building the bits
99 --------------------------
101 To just build everything, from the top level:
109 Building individual parts of the tree
110 -------------------------------------
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.
118 After 'make boot', 'make' will build everything.
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.
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.
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.
141 GhcStage2HcOpts = -O0 -DDEBUG
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).
151 To turn up everything to the max, for running performance tests for
154 SRC_HC_OPTS = -H64m -O2
158 You can even add some more aggresive options, such as
159 -fliberate-case-threshold50, -funfolding-use-threshold50.
165 A rough roadmap to the source tree:
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
182 The GHC Developer's Wiki
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
191 Full documentation on the build system.
192 http://www.haskell.org/ghc/docs/latest/html/building/index.html
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/
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
212 Happy Hacking! --The GHC Team