Skip to content

nick8325/haiku-ghc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

You will need:
1. A Linux machine with GHC on.
2. A Haiku machine without GHC on, running GCC 4.
3. The GHC 7.8.3 source code.
4. The Haiku source code.

Here is how I did it. This will give you a working Haiku version of
GHC including GHCi etc., cross-compiled from your Linux machine.

Part 1: building a C cross-compiler for Haiku
---------------------------------------------

We'll need to put the cross-compiler in /system/develop on the Linux
machine, because that's where gcc lives on Haiku and they need to be
in the same place (isn't it lovely!)

So:

$ sudo mkdir /system
$ sudo chown your_user_name /system

Now build Haiku (probably some of this is unnecessary):

$ cd wherever_haiku_is
$ ./configure --build-cross-tools x86 wherever_buildtools_are
$ jam -j4 haiku-image

Now we'll take bits of the stuff that got built and turn them into a
grotesque mutant cross-compiler:

$ mkdir -p /system/develop
$ cp -r generated/cross-tools-x86 /system/develop/tools
$ cp -r headers/{os,os/support,posix,libs/iconv,libs/ncurses}/* headers/config /system/develop/tools/i586-pc-haiku/include
$ cp $(find generated/objects/haiku/x86/release/system/glue -name '*.o') /system/develop/tools/i586-pc-haiku/lib
$ cp $(find generated/objects/haiku/x86/release -name libroot.so -or -name libiconv.a -or -name libncurses.a) /system/develop/tools/i586-pc-haiku/lib

Part 2: building GHC
--------------------

Extract GHC 7.8.3 and apply the two patches in the ghc-patches directory:
  ghc-patches/0001-Haiku-patches.patch
  ghc-patches/0002-Cross-compiling-patches.patch

Try building it as follows:

$ perl boot
$ ./configure \
    --prefix=/system/non-packaged/ghc-cross \
    --target=i586-pc-haiku \
    --with-gcc=/system/develop/tools/bin/i586-pc-haiku-gcc \
    --with-ld=/system/develop/tools/bin/i586-pc-haiku-ld \
    --with-ar=ar --with-nm=nm --with-ranlib=ranlib --with-objdump=objdump
$ make

This will work for a while but eventually the build script will try to
run a Haiku-compiled version of one program, dll-split, which will
segfault. Go into utils/dll-split/ghc.mk, and change the 1 in the last
line (which is the phase when dll-split should be built) to a 0.
Then run:

$ rm -r utils/dll-split/dist-install
$ make
$ make install

Now it will succeed! But 'make install' installs a Linux version of
unlit by mistake. Replace it with a Haiku version by running:

$ /system/develop/tools/bin/i586-pc-haiku-gcc utils/unlit/unlit.c \
    -o /system/non-packaged/ghc-cross/lib/i586-pc-haiku-ghc-7.8.3/unlit

If you also end up with a Linux version of ghc-pkg (I did once but
seemingly not any more), replace it by running:

$ inplace/bin/ghc-stage1 --make -iutils/ghc-pkg -iutils/ghc-pkg/dist/build Main \
    -o /system/non-packaged/ghc-cross/lib/i586-pc-haiku-ghc-7.8.3/bin/ghc-pkg

Now, just copy /system/non-packaged/ghc-cross over to Haiku!
You will need the ncurses_devel and libiconv_devel packages installed.

Lastly, go into the bin directory and make some nice symlinks, like
linking i586-pc-haiku-ghc to ghc. The build script doesn't make enough
and e.g. GHCi will only work once the right symlinks are there.
Just make the obvious ones and everything should work!

Part 3: building GHC on Haiku
-----------------------------

Now let's build a self-hosted compiler on Haiku, the sane way.

Extract the GHC tarball on Haiku and apply the patch
  ghc-patches/0001-Haiku-patches.patch
but NOT the second, cross-compiling, patch.

Then just build - everything should work! Don't forget to use --prefix
as /usr/local is not very Haiku-friendly.

To get cabal-install running, you will need to build several packages
by hand. At time of writing you need the following packages:
  Cabal-1.20.0.2
  cabal-install-1.20.0.3
  HTTP-4000.2.18
  mtl-2.2.1
  network-2.5.0.0
  parsec-3.1.7
  random-1.0.1.3
  stm-2.4.3
  text-1.2.0.0
  transformers-0.4.1.0
  zlib-0.5.4.1

Fetch these on a machine with a working cabal-install by using cabal
unpack, then transfer them over to Haiku. Note, some of these packages
are not the latest version, so include the version number when running
cabal unpack!

The network package fails to build on Haiku. Apply the patch
network.patch from this repository.

Then build and install each package with
  runghc Setup.lhs configure --prefix=$PREFIX
  runghc Setup.lhs build
  runghc Setup.lhs install
where $PREFIX is wherever you chose to install GHC - make sure to
specify it, otherwise Cabal will default to /usr/local.
Hopefully it will work!

About

Instructions+patches for building GHC for Haiku

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published