Getting started with the build system

There is more complete documentation for the build system later on in this guide (see Building/Using), but this page gives a quick overview of how to get around the GHC build system.

Before starting your build

You need to configure your build: which things to build, how much optimisation to use, whether to build profiling libraries, and so on. If you don't do this, then you get everything, and it will be optimised to the hilt, which means the build will take a Very Long Time. This is fine if you wanted to build GHC for installation and use, but not if you're building GHC to do some development work on it.

To configure your build, create the file mk/build.mk from the sample:

$ cp mk/build.mk.sample mk/build.mk

and then edit mk/build.mk to select the build you want. If you're not sure what you
want, just uncommenting this line

Cleaning

there's also make distclean, which will clean files that are generated by configure, and make maintainer-clean, which cleans everything that is not in the source repository.

You can clean just a part of the tree, e.g. the RTS:

$ cd rts
$ make clean

Validating

Another way to build GHC is to run the validate script, which does a build of GHC from scratch (it does make distclean first), using standard settings, and then runs the testsuite. If validate passes without any errors, then it is ok to submit the patches from your tree.

Parallel builds

The GHC build system works with make's -j flag, which spawns multiple compile processes in parallel. Even on a single processor machine it's usually worthwhile using at least make -j2, because the I/O will be overlapped with compute-intensive compilation. On a multicore machine, higher -j values will speed up the build even more.

Running GHC from the build tree

You don't need to install GHC to use it. After the build has completed, you can run GHC like this:

$ ./inplace/bin/ghc-stage2

and to start GHCi, just add the --interactive flag. You can also see what packages have been built: