Hi,
I intend to use Haskell on embedded systems (ARM and MIPS), where porting and even installing a compiler is not an option.
So
I definitively need a cross-compiler, and to my dismay I have find out
that there is by now no Haskell compiler distribution with this
capacity.
So. I have tried to modify the source of nhc98 so that it supports being configured as a cross-compiler.
The result is in the attached patch.
In
the current state it makes an error during the compilation (
cabal-parse is probably not compiled with the correct compiler ) but
the result of "make install" is able to cross-compile correctly the
program:
main = print("hello world") .
So I send the patch as it in the hope that others will have a look at it and even finish it (hint, hint).
I have somewhat the feeling we are very close to get a fully working cross-compiler
SHORTCOMINGS:
This patch is ugly. Please consider it as something experimental rather as a true proposal.
* The name of the cross-compiler is hard coded in nhc98.inst, so if you want to test it, you must adapt that.
* it uses the presence of a environment variable (TARGET) to know if a
cross-compiler is wished. It should be a "--target" flag to
./configure, but I was not sure how to implement it at best ( by the
way, would it not be better to use the GNU autotools for that ? )
* As I said, the compilation doesn't even complete
* I had to remove the -m32 flag because it was not supported by the version of the ARM GCC cross-compiler I have installed.
HOW TO TEST
$ patch -p 1 < ../nhc98-1.20-with-cross
-compilation.patch1
$ CC=/usr/local/uclibc-0.9.28-3/arm/bin/arm-linux-gcc TARGET=arm-linux ./configure --prefix=/home/sylvain/bin/nhc98-1.20-arm-linux
$ TARGET=arm-linux make basic
$ TARGET=arm-linux make install
As a result:
sylvain@portable:/tmp$ TARGET=arm-linux /home/sylvain/bin/nhc98-1.20-arm-linux/bin/nhc98 -v /tmp/toto.hs -o /tmp/toto
/home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/nhc98comp +RTS -RTS -P/home/sylvain/bin/nhc98-1.20-arm-linux/include/nhc98/packages/base -I. -P/home/sylvain/bin/nhc98-1.20-arm-linux/include/nhc98 /tmp/toto.hs /tmp/toto.hs /tmp/toto.11658.hi /tmp/toto.11658.hc
rm /tmp/toto.11658.hi
/usr/local/uclibc-0.9.28-3/arm/bin/arm-linux-gcc -D__NHC__=120 -x c -S -DLOW_BYTE_FIRST -I/home/sylvain/bin/nhc98-1.20-arm-linux/include/nhc98/ /tmp/toto.11658.hc -o /tmp/toto.11658.s
rm /tmp/toto.11658.hc
/usr/local/uclibc-0.9.28-3/arm/bin/arm-linux-gcc -D__NHC__=120 -c -o /tmp/toto.o /tmp/toto.11658.s
rm /tmp/toto.11658.s
/home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/nhc98heap | /usr/local/uclibc-0.9.28-3/arm/bin/arm-linux-gcc -D__NHC__=120 -x c -c -o /tmp/nhc11658.o -
/usr/local/uclibc-0.9.28-3/arm/bin/arm-linux-gcc -D__NHC__=120 -o /tmp/toto /tmp/toto.o /home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/main.o /home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/mutlib.o /home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/mutator.o /home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/Prelude.a /home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/Runtime.a /home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/Prelude.a /home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/Runtime.a /home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/Prelude.a /home/sylvain/bin/nhc98-1.20-arm-linux/lib/nhc98/arm-linux/Runtime.a /tmp/nhc11658.o -lm
rm -f /tmp/nhc11658.o /tmp/nhc11658.c
on my ARM system ( running on a Qemu image downloaded from the Qemu site ):
$./toto
hello world
nice :)
I hope this patch will wake some interest in the developers of nhc98.
Having the ability to work as cross-compiler would be a bonus for a
compiler, and more generally for the use of the Haskell language in
embedded systems.
I personnaly do think this is a must have.
Greetings,
Sylvain
PS: the patch is against the distribution nhc98-1.20. The head of the darcs repository seems unable to build for now.