wiki:Building/Preparation/Linux

Setting up a Linux system for building GHC

If you're on a recent Linux system, then you should be able to get a working build environment by installing the following packages using your system's package manager.

Docker

If you are familiar with docker, this is a 1 step install for a development image (ghc build requirements plus a few development related tools). First cd into your ghc directory that you should check out according to Building/GettingTheSources, then

   sudo docker run --rm -i -t -v `pwd`:/home/ghc gregweber/ghc-haskell-dev /bin/bash

That's it! This mounts your ghc source code into the docker container. This way you can still hack on ghc with Emacs, etc, but you are just building from the docker container. Note that arc (the GHC patch submission tool) is installed in the image (although you can also use it from your docker host) along with vim-tiny for editing commit messages.

Send pull requests to https://github.com/gregwebs/ghc-docker-dev if something is out-of-date.

Fedora

Install the required tools using the following command for Fedora 22 and later (for earlier versions of Fedora, use yum instead of dnf):

   sudo dnf install glibc-devel ncurses-devel gmp-devel autoconf automake libtool gcc make perl python ghc happy alex git

For building the documentation: (User's Guide and Cabal guide): (optional)

   # GHC > 7.10 (untested)
   sudo dnf install python-sphinx
   # GHC <= 7.10
   sudo dnf install docbook-utils docbook-utils-pdf docbook-style-xsl

other packages that are useful for development: (optional)

   sudo dnf install strace patch

Now the system should be ready to build GHC.

For a quickstart, follow the commands listed under:

https://github.com/ghc/ghc#building--installing

Debian, Ubuntu, and other Debian-based systems

You can make sure you have all dependencies by

   sudo apt-get build-dep ghc

But this might install some packages you do not use in your system (e.g. Sphinx). Alternatively install the following:

   sudo apt-get install git autoconf automake libtool make gcc g++ \
     libgmp-dev ncurses-dev libtinfo-dev python3 xz-utils

(ncurses-dev is needed by the terminfo package, and g++ is needed by a couple of tests, ghcilink003 and ghcilink006).

Optional: install LLVM from <http://apt.llvm.org> (only necessary to make the -fllvm flag work). Commentary/Compiler/Backends/LLVM/Installing will tell you which version to install.

Due to the nature of Debian, you may have difficulty building GHC >7.6 due to version incompatibilities with the Happy and Alex packages. To alleviate this issue simply install both packages using the haskell-platform provided cabal.

   cabal install alex happy

If you install alex and happy using cabal as shown above, you will need to add the cabal installation directory to PATH before running the configure script.

   export PATH=$HOME/.cabal/bin:$PATH

For building the documentation (User's Guide):

   # GHC > 7.10:
   sudo apt-get install python-sphinx texlive-xetex texlive-fonts-recommended fonts-lmodern texlive-latex-recommended texlive-latex-extra
   # GHC <= 7.10:
   sudo apt-get install dblatex docbook-xsl docbook-utils libxml2-utils texlive-font-utils

other packages that are useful for development:

   sudo apt-get install linux-tools-generic xutils-dev

The package linux-tools includes perf, see Debugging/LowLevelProfiling/Perf. The package xutils-dev provides the lndir program, need for running make sdist and useful for maintaining a separate build tree, see Building/Using.

For validating patches :

Arch

Install the required tools:

   sudo pacman -S ghc ghc-static perl gcc make happy alex cabal-install autoconf automake python python-sphinx libedit

Nix/NixOS

First, you need to clone Nixpkgs, so you could use recent Nix recipes:

   git clone https://github.com/NixOS/nixpkgs  

Then, you can build the environment needed for compiling HEAD (assuming that the nixpkgs directory is in /home/user):

   cd ~
   nix-shell '<nixpkgs>' -A haskell.compiler.ghcHEAD

Finally, clone, configure, and build GHC (see Newcomers for details), but replace the usual configure && make with the Nix build phases:

   git clone --recursive https://github.com/ghc/ghc
   cd ghc/
   # patchPhase (sometimes this is necessary if there are patches which need to be applied as of Dec 2016 with the unstable channel it is unnecessary)

   #edit mk/build.mk.sample as normal
   # This command needs to be used so that the right paths to libraries are passed to ./configure
   configurePhase 
   buildPhase
   # edit build.mk to remove the comment marker # on the line stage=2

If you have come this way it is assumed you know what you are doing! The ghcHEAD derivation does not include the dependencies needed for the test suite. I (mpickering, Dec 2016) don't know exactly what these dependencies are but you should add them to your environment by defining a suitable shell.nix.

Enable parallel builds in the nix build environment:

   export NIX_BUILD_CORES=4

shell.nix

If you need more control over your GHC build environment there is a shell.nix file that defines (hopefully) all dependencies: https://github.com/supersven/ghc-shell.nix You can use it as is or a base for your own.

Last modified 2 months ago Last modified on Oct 5, 2017 2:48:00 AM