Bootstrapping GHC for a new architecture

Note: In order to be able to bootstrap GHC for a new architecture, the architecture has to be known to GHC. A minimal patch to add support for a new architecture is discussed in

Cross-compiling ghc stage1

To bootstrap ghc for a new architecture, it needs to be cross-compiled first. This requires a cross-compiler toolchain (gcc, binutils etc) for the target architecture as well as a working ghc installation on your host architecture.

1. Install the ghc build dependencies:

   $ apt build-dep ghc

2. Install the gcc cross toolchain for the target architecture:

   $ apt install gcc-m68k-linux-gnu g++-m68k-linux-gnu cpp-m68k-linux-gnu

3. Download a not too old version of ghc, we use 8.0.1:

   $ mkdir m68k
   $ cd m68k
   $ wget

4. Install libncurses5 and libncurses5-dev for the target architecture on the host machine with the help of MultiArch:

  (as root)
  $ apt install debian-ports-archive-keyring
  $ echo "deb [arch=m68k] unstable main" >> /etc/apt/sources.list
  $ dpkg --add-architecture m68k
  $ apt update
  $ apt install libncurses5:m68k libncurses5-dev:m68k
  $ logout

5. Unpack the source tarball:

   $ tar xf ghc_8.0.1.orig.tar.xz

6. Patch the main makefile to fix a problem with the installation of the stage2 compiler:

diff --git a/ b/
index e095ffd..508746d 100644
--- a/
+++ b/
@@ -955,8 +957,12 @@ INSTALLED_PACKAGE_CONF=$(DESTDIR)$(topdir)/package.conf.d
 # Install packages in the right order, so that ghc-pkg doesn't complain.
 # Also, install ghc-pkg first.
 ifeq "$(Windows_Host)" "NO"
+# Use the inplace/stage1 versions for installation,
+# since the installed versions are built for the target

7. Copy mk/ to mk/ and enable "quick-cross":

   $ cp -av mk/ mk/
   $ sed -i 's/#\(BuildFlavour\s*\=\s*quick-cross\)/\1/g' mk/

8. Run configure with $ARCH-linux-gnu as TARGET where $ARCH is your architecture:

   $ ./configure --enable-unregisterised --target=m68k-linux-gnu

9. Run "make".

   $ make

After this, you will end up with a stage1 compiler that can be installed on the host system with "make install".

Building stage2

To get the stage2 compiler which will be able to run on the target system, edit mk/flavours/ to set "?Stage1Only" from "YES" to "NO", then run make again:

   $ sed -i 's/\(Stage1Only\s*\=\s*\)YES/\1NO/g' mk/flavours/
   $ make install DESTDIR=/path/for/target-ghc

Building the ghc Debian packages on the target

1. Make sure ghc is properly installed and working.

2. Download the source of the ghc package on the target system:

   $ dget -u

3. Install the build dependencies for ghc on the target system:

   $ apt-get install debhelper devscripts dh-autoreconf autotools-dev grep-dctrl pkg-config libgmp-dev libffi-dev binutils libncurses5-dev python-sphinx dpkg-dev

4. Remove "ghc" and "haskell-devscripts-minimal" from debian/control in GHC package source.

5. Download haskell-devscripts-minimal and install into chroot root with "dpkg-deb -x haskell-devscripts-minimal*deb".

6. Build the ghc package with:

   $ dpkg-buildpackage -B

Bootstrapping happy and alex

Once ghc has been bootstrapped for the new architecture, happy and alex need to be bootstrapped as well. For this, these two packages support build profiles which can be directly activated with sbuild and both are build natively:

First happy:

$ mkdir happy
$ cd happy
$ dget -u
$ sbuild --arch=m68k --no-arch-all --profiles=stage1 -d unstable happy_1.19.5-5.dsc
$ debsign happy_1.19.5-5_m68k.changes
$ dupload --to debian-ports happy_1.19.5-5_m68k.changes

Install the newly built happy package into your unstable chroot and build alex analogous to happy:

$ mkdir alex
$ cd alex
$ dget -u
$ sbuild --arch=m68k --no-arch-all --profiles=stage1 -d unstable alex_3.1.6-1.dsc
$ debsign alex_3.1.6-1_m68k.changes
$ dupload --to debian-ports alex_3.1.6-1_m68k.changes