-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
125 lines (96 loc) · 4.38 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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!