Hi,<br><br>( I am not sure if my first mail was correctly sent. I send it again with the patch in the body )<br><br>I intend to use Haskell on embedded systems (ARM and MIPS), where porting and even installing a compiler is not an option.<br>
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.<br>
<br>I have tried to modify the source of nhc98 to make it supports being configured as a cross-compiler. <br>The result is in the attached patch.<br><br>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: <br>
main = print("hello world") .<br><br>So I send the patch as it in the hope that others will have a look at it and even finish it (hint, hint). <br>I have somewhat the feeling we are very close to get a fully working cross-compiler <br>
<br>SHORTCOMINGS:<br><br>This patch is ugly. Please consider it as something experimental rather as a true proposal.<br>* The name of the cross-compiler is hard coded in nhc98.inst, so if you want to test it, you must adapt that.<br>
* 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 ? )<br>
* As I said, the compilation doesn't even complete<br>* I had to remove the -m32 flag because it was not supported by the version of the ARM GCC cross-compiler I have installed.<br><br>HOW TO TEST<br><br>$ patch -p 1 < ../nhc98-1.20-with-cross<div>
-compilation.patch1<br>
$ 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<br>$ TARGET=arm-linux make basic<br>$ TARGET=arm-linux make install<br><br>As a result:<br>
<br>sylvain@portable:/tmp$ TARGET=arm-linux /home/sylvain/bin/nhc98-1.20-arm-linux/bin/nhc98 -v /tmp/toto.hs -o /tmp/toto<br>/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<br>
rm /tmp/toto.11658.hi<br>/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<br>rm /tmp/toto.11658.hc<br>
/usr/local/uclibc-0.9.28-3/arm/bin/arm-linux-gcc -D__NHC__=120 -c -o /tmp/toto.o /tmp/toto.11658.s<br>rm /tmp/toto.11658.s<br>/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 -<br>
/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<br>
rm -f /tmp/nhc11658.o /tmp/nhc11658.c<br><br>on my ARM system ( running on a Qemu image downloaded from the Qemu site ):<br>$./toto<br>hello world<br><br>nice :)<br><br>I hope this patch will wake some interest in the developers of nhc98. <br>
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.<br>I personnaly do think this is a must have.<br><br>Greetings,<br><font color="#888888"><font color="#888888">
Sylvain<br></font></font><br>PS: the patch is against the distribution nhc98-1.20. The head of the darcs repository seems unable to build for now.<br><br>BEGIN OF PATCH<br>diff -Naur nhc98-1.20-orig/configure nhc98-1.20/configure<br>
--- nhc98-1.20-orig/configure 2007-11-22 14:05:24.000000000 +0100<br>+++ nhc98-1.20/configure 2008-04-02 20:36:56.000000000 +0200<br>@@ -36,11 +36,30 @@<br> INSTALLDIR=/usr/local<br> <br> USER=${USER-`whoami 2>/dev/null`}<br>
+<br>+if [ "$TARGET" != "" ]<br>+then<br>+MACHINE=`script/harch`<br>+case $MACHINE in<br>+ powerpc-Darwin[56]) CCC=${CC-cc}; STRIP=${STRIP-strip};;<br>+ *) CCC=${CC-gcc}; STRIP=${STRIP-strip};;<br>
+esac<br>+# in case of building a cross-compiler, CCC is the cross-compiler CC<br>+# and HOST the local C compliler<br>+HOSTCCC=gcc<br>+HOSTSTRIP=strip<br>+<br>+else<br> MACHINE=`script/harch`<br>+<br> case $MACHINE in<br>
- powerpc-Darwin[56]) CCC=${CC-cc};;<br>- *) CCC=${CC-gcc};;<br>+ powerpc-Darwin[56]) CCC=${CC-cc}; STRIP=${STRIP-strip} ;;<br>+ *) CCC=${CC-gcc};STRIP=${STRIP-strip} ;;<br> esac<br>+HOSTCCC=${CCC}<br>
+HOSTSTRIP=${STRIP}<br>+fi<br>+<br> PWD=`pwd`<br> case $OS in<br> CYGWIN*) PWD=`cygpath -w "$PWD" | tr '\\\\' '/'`<br>@@ -334,7 +353,7 @@<br> }<br> }<br> !!!<br>- $CCC -m32 $COPTS -o endian endian.c<br>
+ $HOSTCCC -m32 $COPTS -o endian endian.c<br> ENDIAN=`./endian`<br> rm -f endian$EXE endian.c<br> echo -n "$ENDIAN "<br>@@ -416,9 +435,9 @@<br> cp src/prelude/DErrNo.p.c src/prelude/$MACHINE/NHC<br>
cp src/prelude/DErrNo.z.c src/prelude/$MACHINE/NHC<br> fi<br>- $CCC $COPTS -o config-errno script/config-errno.c && \<br>+ $HOSTCCC $COPTS -o config-errno script/config-errno.c && \<br> ./config-errno >targets/$MACHINE/Errno.hs && rm -f ./config-errno$EXE<br>
- $CCC $COPTS -o errnogen script/errnogen.c && \<br>+ $HOSTCCC $COPTS -o errnogen script/errnogen.c && \<br> ./errnogen >DErrNo.hs && rm -f ./errnogen$EXE<br> if diff DErrNo.hs src/prelude/$MACHINE/NHC/DErrNo.hs >/dev/null<br>
then<br>@@ -544,6 +563,9 @@<br> echo "CURSES=\"$CURSES\"";<br> echo "EXE=$EXE";<br> echo "CC=$CCC";<br>+ echo "HOSTCC=$HOSTCCC";<br>+ echo "STRIP=$STRIP" ;<br>
+ echo "HOSTSTRIP=$HOSTSTRIP" ;<br> echo "COPTS=\"$COPTS\"";<br> echo "GHCSYM=`cat targets/$MACHINE/ghcsym || true`";<br> echo "TRUE=$TRUE";<br>@@ -823,6 +845,9 @@<br>
echo "BUILDDIR=$BUILDDIR" ;<br> echo "RTSFLAG=$RTSFLAG" ;<br> echo "CC=$CCC" ;<br>+ echo "HOSTCC=$HOSTCCC" ;<br>+ echo "STRIP=$STRIP" ;<br>+ echo "HOSTSTRIP=$HOSTSTRIP" ;<br>
echo "COPTS=\"$COPTS\"";<br> echo "ENDIAN=$ENDIAN" ;<br> echo "HEAP=$HEAP" ;<br>diff -Naur nhc98-1.20-orig/Makefile.inc nhc98-1.20/Makefile.inc<br>--- nhc98-1.20-orig/Makefile.inc 2007-11-22 14:05:04.000000000 +0100<br>
+++ nhc98-1.20/Makefile.inc 2008-04-02 17:30:59.000000000 +0200<br>@@ -1,7 +1,8 @@<br> ### Configurable variables:<br> <br> OPT = -O3<br>-ARCH = -m32<br>+#ARCH = -m32<br>+ARCH = <br> <br> # CC = actually sourced from LIBDIR/MACHINE/config<br>
INSTALL = cp<br>diff -Naur nhc98-1.20-orig/script/harch nhc98-1.20/script/harch<br>--- nhc98-1.20-orig/script/harch 2007-11-22 11:32:51.000000000 +0100<br>+++ nhc98-1.20/script/harch 2008-04-02 17:31:35.000000000 +0200<br>
@@ -8,6 +8,12 @@<br> OS=<br> REL=<br> <br>+if [ "$TARGET" != "" ]<br>+then<br>+ echo $TARGET<br>+ exit 0<br>+fi<br>+<br> # Unfortunately, there are a variety of incompatible<br> # ways of detecting architecture, so try them all!<br>
<br>diff -Naur nhc98-1.20-orig/script/nhc98.inst nhc98-1.20/script/nhc98.inst<br>--- nhc98-1.20-orig/script/nhc98.inst 2007-11-22 12:22:16.000000000 +0100<br>+++ nhc98-1.20/script/nhc98.inst 2008-04-02 23:59:08.000000000 +0200<br>
@@ -70,7 +70,13 @@<br> <br> MAINROUTINE=$NHC98LIBDIR/$MACHINE/main<br> <br>+if [ "$TARGET" != "" ]<br>+then<br>+CC="/usr/local/uclibc-0.9.28-3/arm/bin/arm-linux-gcc -D__NHC__=$VERSIONNUM"<br>
+else<br> CC=${CC-gcc}" -m32 -D__NHC__=$VERSIONNUM"<br>+fi<br>+<br> CPPHS="$NHC98LIBDIR/$MACHINE/cpphs"<br> if test $USINGRTS -eq 0 ; then<br> CPPHS="$CPPHS -"<br>diff -Naur nhc98-1.20-orig/src/compiler98/Makefile.hat nhc98-1.20/src/compiler98/Makefile.hat<br>
--- nhc98-1.20-orig/src/compiler98/Makefile.hat 2007-11-22 11:34:28.000000000 +0100<br>+++ nhc98-1.20/src/compiler98/Makefile.hat 2008-04-02 20:23:20.000000000 +0200<br>@@ -43,7 +43,7 @@<br> $(TARGET): ${OBJDIR} $(OBJDIR)/$(HC) $(SRCS)<br>
hmake -$(HC) $(HMAKEFLAGS) -d $(OBJDIR) HatTrans<br> mv $(OBJDIR)/HatTrans$(EXE) $(TARGET)<br>- strip $(TARGET)<br>+ $(STRIP) $(TARGET)<br> ${OBJDIR}:<br> mkdir -p ${OBJDIR}<br> $(OBJDIR)/$(HC):<br>
diff -Naur nhc98-1.20-orig/src/runtime/Integer/Makefile nhc98-1.20/src/runtime/Integer/Makefile<br>--- nhc98-1.20-orig/src/runtime/Integer/Makefile 2007-11-22 11:32:51.000000000 +0100<br>+++ nhc98-1.20/src/runtime/Integer/Makefile 2008-04-02 17:36:38.000000000 +0200<br>
@@ -51,7 +51,7 @@<br> $(OBJDIR)/cre-mparam > tmp-$@<br> mv tmp-$@ $@<br> $(OBJDIR)/cre-mparam: cre-mparam.c gmp.h haskell2c.h <br>- $(CC) $(CFLAGS) `if [ x$(firstword $^) = x ]; \<br>+ $(HOSTCC) $(CFLAGS) `if [ x$(firstword $^) = x ]; \<br>
then echo cre-mparam.c; \<br> else echo $(firstword $^); fi` -o $@<br> <br>diff -Naur nhc98-1.20-orig/src/runtime/Makefile nhc98-1.20/src/runtime/Makefile<br>
--- nhc98-1.20-orig/src/runtime/Makefile 2007-11-22 11:32:51.000000000 +0100<br>+++ nhc98-1.20/src/runtime/Makefile 2008-04-02 17:38:23.000000000 +0200<br>@@ -66,6 +66,6 @@<br> cd Mk; $(MAKE) objdir<br>
<br> $(DST)/nhc98heap$(EXE): nhc98heap.c<br>- $(CC) $(ARCH) $(shell echo ${COPTS}) -o $@ $<<br>+ $(HOSTCC) $(ARCH) $(shell echo ${COPTS}) -o $@ $<<br> $(STRIP) $@<br><br>END OF PATCH<br></div>