Bootstrapping GHC for a new architecture

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 http://snapshot.debian.org/archive/debian/20160521T223144Z/pool/main/g/ghc/ghc_8.0.1.orig.tar.xz

4. Download ncurses libraries and headers for the target architecture, unpack both using "dpkg-deb":

  $ mkdir ncurses
  $ cd ncurses
  $ wget http://snapshot.debian.org/archive/debian-ports/20160326T020526Z/pool-m68k/main/n/ncurses/libncurses5-dev_6.0%2B20160319-1_m68k.deb
  $ wget http://snapshot.debian.org/archive/debian-ports/20160326T020526Z/pool-m68k/main/n/ncurses/libncurses5_6.0%2B20160319-1_m68k.deb
  $ dpkg-deb -x libncurses5-dev_6.0+20160319-1_m68k.deb .
  $ dpkg-deb -x libncurses5_6.0+20160319-1_m68k.deb .
  $ cd ..

5. Unpack the source tarball:

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

6. Copy mk/build.mk.sample to mk/build.mk and enable "quick-cross":

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

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

   $ ./configure --enable-unregisterised --target=m68k-linux-gnu --with-curses-libraries=~/m68k/ghc/ncurses/usr/lib/m68k-linux-gnu/

8. 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/quick-cross.mk to set "?Stage1Only" from "YES" to "NO", then run make again:

   $ sed 's/\(Stage1Only\s*\=\s*\)YES/\1NO/g' mk/flavours/quick-cross.mk
   $ make install /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 http://snapshot.debian.org/archive/debian-debug/20160522T042329Z/pool/main/g/ghc/ghc_8.0.1-1.dsc

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

   $ apt install ...

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 http://snapshot.debian.org/archive/debian/20151222T094900Z/pool/main/h/happy/happy_1.19.5-5.dsc
$ 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 http://snapshot.debian.org/archive/debian/20160111T094634Z/pool/main/a/alex/alex_3.1.6-1.dsc
$ 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