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 &quot;make install&quot; is able to cross-compile correctly the
program: <br>
main = print(&quot;hello world&quot;) .<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&nbsp; 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 &quot;--target&quot; 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&#39;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 &lt; ../nhc98-1.20-with-cross<div>

-compilation.patch1<br>
$ CC=/usr/local/uclibc-0.9.28-3/arm/bin/arm-linux-gcc&nbsp; 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&nbsp;&nbsp; | /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&nbsp;&nbsp; 2007-11-22 14:05:24.000000000 +0100<br>+++ nhc98-1.20/configure&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2008-04-02 20:36:56.000000000 +0200<br>@@ -36,11 +36,30 @@<br>&nbsp;INSTALLDIR=/usr/local<br>&nbsp;<br>&nbsp;USER=${USER-`whoami 2&gt;/dev/null`}<br>
+<br>+if [ &quot;$TARGET&quot; != &quot;&quot; ]<br>+then<br>+MACHINE=`script/harch`<br>+case $MACHINE in<br>+&nbsp; powerpc-Darwin[56]) CCC=${CC-cc}; STRIP=${STRIP-strip};;<br>+&nbsp; *)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;MACHINE=`script/harch`<br>+<br>&nbsp;case $MACHINE in<br>
-&nbsp; powerpc-Darwin[56]) CCC=${CC-cc};;<br>-&nbsp; *)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CCC=${CC-gcc};;<br>+&nbsp; powerpc-Darwin[56]) CCC=${CC-cc}; STRIP=${STRIP-strip} ;;<br>+&nbsp; *)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CCC=${CC-gcc};STRIP=${STRIP-strip} ;;<br>&nbsp;esac<br>+HOSTCCC=${CCC}<br>
+HOSTSTRIP=${STRIP}<br>+fi<br>+<br>&nbsp;PWD=`pwd`<br>&nbsp;case $OS in<br>&nbsp;&nbsp; CYGWIN*) PWD=`cygpath -w &quot;$PWD&quot; | tr &#39;\\\\&#39; &#39;/&#39;`<br>@@ -334,7 +353,7 @@<br>&nbsp;&nbsp; }<br>&nbsp;}<br>&nbsp;!!!<br>-&nbsp;&nbsp;&nbsp; $CCC -m32 $COPTS -o endian endian.c<br>
+&nbsp;&nbsp;&nbsp; $HOSTCCC -m32 $COPTS -o endian endian.c<br>&nbsp;&nbsp;&nbsp;&nbsp; ENDIAN=`./endian`<br>&nbsp;&nbsp;&nbsp;&nbsp; rm -f endian$EXE endian.c<br>&nbsp;&nbsp;&nbsp;&nbsp; echo -n &quot;$ENDIAN &quot;<br>@@ -416,9 +435,9 @@<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cp src/prelude/DErrNo.p.c&nbsp; src/prelude/$MACHINE/NHC<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cp src/prelude/DErrNo.z.c&nbsp; src/prelude/$MACHINE/NHC<br>&nbsp;&nbsp; fi<br>-&nbsp; $CCC $COPTS -o config-errno script/config-errno.c &amp;&amp; \<br>+&nbsp; $HOSTCCC $COPTS -o config-errno script/config-errno.c &amp;&amp; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ./config-errno &gt;targets/$MACHINE/Errno.hs &amp;&amp; rm -f ./config-errno$EXE<br>
-&nbsp; $CCC $COPTS -o errnogen script/errnogen.c &amp;&amp; \<br>+&nbsp; $HOSTCCC $COPTS -o errnogen script/errnogen.c &amp;&amp; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ./errnogen &gt;DErrNo.hs &amp;&amp; rm -f ./errnogen$EXE<br>&nbsp;&nbsp; if diff DErrNo.hs src/prelude/$MACHINE/NHC/DErrNo.hs &gt;/dev/null<br>
&nbsp;&nbsp; then<br>@@ -544,6 +563,9 @@<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;CURSES=\&quot;$CURSES\&quot;&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;EXE=$EXE&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;CC=$CCC&quot;;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;HOSTCC=$HOSTCCC&quot;;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;STRIP=$STRIP&quot; ;<br>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;HOSTSTRIP=$HOSTSTRIP&quot; ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;COPTS=\&quot;$COPTS\&quot;&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;GHCSYM=`cat targets/$MACHINE/ghcsym || true`&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;TRUE=$TRUE&quot;;<br>@@ -823,6 +845,9 @@<br>
&nbsp;&nbsp; echo &quot;BUILDDIR=$BUILDDIR&quot; ;<br>&nbsp;&nbsp; echo &quot;RTSFLAG=$RTSFLAG&quot; ;<br>&nbsp;&nbsp; echo &quot;CC=$CCC&quot; ;<br>+&nbsp; echo &quot;HOSTCC=$HOSTCCC&quot; ;<br>+&nbsp; echo &quot;STRIP=$STRIP&quot; ;<br>+&nbsp; echo &quot;HOSTSTRIP=$HOSTSTRIP&quot; ;<br>
&nbsp;&nbsp; echo &quot;COPTS=\&quot;$COPTS\&quot;&quot;;<br>&nbsp;&nbsp; echo &quot;ENDIAN=$ENDIAN&quot; ;<br>&nbsp;&nbsp; echo &quot;HEAP=$HEAP&quot; ;<br>diff -Naur nhc98-1.20-orig/Makefile.inc nhc98-1.20/Makefile.inc<br>--- nhc98-1.20-orig/Makefile.inc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-11-22 14:05:04.000000000 +0100<br>
+++ nhc98-1.20/Makefile.inc&nbsp;&nbsp;&nbsp;&nbsp; 2008-04-02 17:30:59.000000000 +0200<br>@@ -1,7 +1,8 @@<br>&nbsp;### Configurable variables:<br>&nbsp;<br>&nbsp;OPT = -O3<br>-ARCH = -m32<br>+#ARCH = -m32<br>+ARCH = <br>&nbsp;<br>&nbsp;# CC = actually sourced from LIBDIR/MACHINE/config<br>
&nbsp;INSTALL = cp<br>diff -Naur nhc98-1.20-orig/script/harch nhc98-1.20/script/harch<br>--- nhc98-1.20-orig/script/harch&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-11-22 11:32:51.000000000 +0100<br>+++ nhc98-1.20/script/harch&nbsp;&nbsp;&nbsp;&nbsp; 2008-04-02 17:31:35.000000000 +0200<br>
@@ -8,6 +8,12 @@<br>&nbsp;OS=<br>&nbsp;REL=<br>&nbsp;<br>+if [ &quot;$TARGET&quot; != &quot;&quot; ]<br>+then<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo $TARGET<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit 0<br>+fi<br>+<br>&nbsp;#&nbsp; Unfortunately, there are a variety of incompatible<br>&nbsp;#&nbsp; ways of detecting architecture, so try them all!<br>
&nbsp;<br>diff -Naur nhc98-1.20-orig/script/nhc98.inst nhc98-1.20/script/nhc98.inst<br>--- nhc98-1.20-orig/script/nhc98.inst&nbsp;&nbsp; 2007-11-22 12:22:16.000000000 +0100<br>+++ nhc98-1.20/script/nhc98.inst&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2008-04-02 23:59:08.000000000 +0200<br>
@@ -70,7 +70,13 @@<br>&nbsp;<br>&nbsp;MAINROUTINE=$NHC98LIBDIR/$MACHINE/main<br>&nbsp;<br>+if [ &quot;$TARGET&quot; != &quot;&quot; ]<br>+then<br>+CC=&quot;/usr/local/uclibc-0.9.28-3/arm/bin/arm-linux-gcc -D__NHC__=$VERSIONNUM&quot;<br>
+else<br>&nbsp;CC=${CC-gcc}&quot; -m32 -D__NHC__=$VERSIONNUM&quot;<br>+fi<br>+<br>&nbsp;CPPHS=&quot;$NHC98LIBDIR/$MACHINE/cpphs&quot;<br>&nbsp;if test $USINGRTS -eq 0 ; then<br>&nbsp;&nbsp; CPPHS=&quot;$CPPHS -&quot;<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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2008-04-02 20:23:20.000000000 +0200<br>@@ -43,7 +43,7 @@<br>&nbsp;$(TARGET): ${OBJDIR} $(OBJDIR)/$(HC) $(SRCS)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hmake -$(HC) $(HMAKEFLAGS) -d $(OBJDIR) HatTrans<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mv $(OBJDIR)/HatTrans$(EXE) $(TARGET)<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strip $(TARGET)<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(STRIP) $(TARGET)<br>&nbsp;${OBJDIR}:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mkdir -p ${OBJDIR}<br>&nbsp;$(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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-11-22 11:32:51.000000000 +0100<br>+++ nhc98-1.20/src/runtime/Integer/Makefile&nbsp;&nbsp;&nbsp;&nbsp; 2008-04-02 17:36:38.000000000 +0200<br>
@@ -51,7 +51,7 @@<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(OBJDIR)/cre-mparam &gt; tmp-$@<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mv tmp-$@ $@<br>&nbsp;$(OBJDIR)/cre-mparam: cre-mparam.c gmp.h haskell2c.h <br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(CC) $(CFLAGS) `if [ x$(firstword $^) = x ];&nbsp;&nbsp; \<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(HOSTCC) $(CFLAGS) `if [ x$(firstword $^) = x ];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then echo cre-mparam.c;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else echo $(firstword $^); fi` -o $@<br>&nbsp;<br>diff -Naur nhc98-1.20-orig/src/runtime/Makefile nhc98-1.20/src/runtime/Makefile<br>
--- nhc98-1.20-orig/src/runtime/Makefile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2007-11-22 11:32:51.000000000 +0100<br>+++ nhc98-1.20/src/runtime/Makefile&nbsp;&nbsp;&nbsp;&nbsp; 2008-04-02 17:38:23.000000000 +0200<br>@@ -66,6 +66,6 @@<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cd Mk;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(MAKE) objdir<br>
&nbsp;<br>&nbsp;$(DST)/nhc98heap$(EXE): nhc98heap.c<br>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(CC) $(ARCH) $(shell echo ${COPTS}) -o $@ $&lt;<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(HOSTCC) $(ARCH) $(shell echo ${COPTS}) -o $@ $&lt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(STRIP) $@<br><br>END OF PATCH<br></div>