MLDonkey Forum Index
Homepage •  Bugs •  Tasks •  Patches •  SF.net Project Page •  ChangeLog •  German forum •  Links •  Wiki •  Downloads
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
How to cross-compile 3.0.7 to ARM?
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    MLDonkey Forum Index -> Alternative platforms
View previous topic :: View next topic  
Author Message
wagle
neophyte


Joined: 29 Mar 2011
Posts: 19

PostPosted: Thu Mar 31, 2011 7:26 pm    Post subject: Reply with quote

I'm about to have the 32 vs 64 bit stuff solved, I think, which will simplify things quite a bit (else you have to run your 64 bit machine in 32 bit mode, change all the gcc to gcc -m32, etc). Hold on / stay tuned / etc.
Back to top
View user's profile Send private message
wagle
neophyte


Joined: 29 Mar 2011
Posts: 19

PostPosted: Fri Apr 01, 2011 5:06 am    Post subject: Reply with quote

Okay, check out https://github.com/wagle/ocaml-cross-compiler, which is a sort of omnibus repo, with two different cross-compilers: inria and ecc

I suggest trying to build them on a 32-bit linux x86_32, and not on a 64 bit x86_64 like I have to do. If this doesn't work for you, let me know, and I'll work on a 32-bit build machine enough to get it to work.

OCAML gets confused about word size when cross-compiling from a 64 bit machine to a 32 bit machine. Known bug, being worked on, hard to fix.


Sprinkled through the repo are "README.wagle" files, so named to stand out with a unique name.


I will be working on merging the ecc sub-repo with the inria sub-repo enough to provide everything MLdonkey needs to build. I'm also waiting for the word size thing to get fixed.

The current strategy is to shadow the ocaml binaries (lib and executables) in /usr/local with ones in /opt/caml-cross-arm (or whatever) by having the latter directory come first in the PATH.

Please ask questions here. I will summarize gathered knowledge in the README.wagle's and the wiki on the above github project.
Back to top
View user's profile Send private message
wagle
neophyte


Joined: 29 Mar 2011
Posts: 19

PostPosted: Fri Apr 01, 2011 6:04 am    Post subject: Reply with quote

Actually, the ecc subrepo is broken unless you revert commit 8f57479c5a37651114e22f501c37eb5ee951a2cc

Sorry, I think I did the repo wrong. I'm currently completely rethinking it. I designed it to get my work done, not for public communication, and I botched it when I tried to get it to do the latter.

I should have something new up in a couple hours.
Back to top
View user's profile Send private message
ygrek
professional


Joined: 20 Mar 2010
Posts: 610

PostPosted: Sat Apr 02, 2011 1:28 pm    Post subject: Reply with quote

I have successfully compiled hello world with ocaml armel cross compiler (using emdebian toolchain). Now to mldonkey Makefile.

Current diff :
Code:

diff --git x86_64-to-arm/inria/ocaml-3.12.0/Makefile x86_64-to-arm/inria/ocaml-3.12.0/Makefile
index 466fb30..0be8fd9 100644
--- x86_64-to-arm/inria/ocaml-3.12.0/Makefile
+++ x86_64-to-arm/inria/ocaml-3.12.0/Makefile
@@ -273,8 +273,8 @@ base.opt: checkstack runtime core ocaml opt-core ocamlc.opt otherlibraries \
 
 # Compile the cross-compiler
 cross:
-   cd boot && cp `which ocamlrun` .
-   cd byterun && cp `which ocamlrun` .
+   cd boot && cp $(BOOT_OCAMLRUN) .
+   cd byterun && cp $(BOOT_OCAMLRUN) .
    cd stdlib; $(MAKE) COMPILER=../boot/ocamlc all
    cd stdlib; cp $(LIBFILES) ../boot
    cd yacc; $(MAKE) all
diff --git x86_64-to-arm/inria/ocaml-3.12.0/config/Makefile x86_64-to-arm/inria/ocaml-3.12.0/config/Makefile
index 3b3bdae..960d711 100644
--- x86_64-to-arm/inria/ocaml-3.12.0/config/Makefile
+++ x86_64-to-arm/inria/ocaml-3.12.0/config/Makefile
@@ -15,8 +15,9 @@
 
 ### Compile-time configuration
 
+BOOT_OCAMLRUN=/opt/ocaml-3.12.0/bin/ocamlrun
 ### begin WAGLE
-PREFIX=/opt/ocaml-cross-arm
+PREFIX=/opt/ocaml-3.12.0-wagle-armel-cross
 SYSTHREAD_SUPPORT=false
 #SYSTHREAD_SUPPORT=true
 SUPPORTS_SHARED_LIBRARIES=true
@@ -48,7 +49,8 @@ TOOLCHAIN=cc
 NATDYNLINK=true
 CMXS=cmxs
 #XGCC=arm-none-linux-gnueabi-
-XXX=/root/proj/1470_Firmware_Source/buildroot-7821TSI/build_arm/staging_dir/usr/bin/arm-linux-uclibcgnueabi-
+#XXX=/root/proj/1470_Firmware_Source/buildroot-7821TSI/build_arm/staging_dir/usr/bin/arm-linux-uclibcgnueabi-
+XXX=arm-linux-gnueabi-
 
 ### end WAGLE
 
@@ -139,7 +141,7 @@ SYSLIB=-l$(1)
 
 ### How to build a static library
 MKLIB=$(TARGET_AR) rc \$(1) \$(2); $(TARGET_RANLIB) \$(1)
-#ml let mklib out files opts = Printf.sprintf "/root/proj/1470_Firmware_Source/buildroot-7821TSI/build_arm/staging_dir/usr/bin/arm-linux-uclibcgnueabi-ar rc %s %s %s; /root/proj/1470_Firmware_Source/buildroot-7821TSI/build_arm/staging_dir/usr/bin/arm-linux-uclibcgnueabi-ranlib %s" out opts files out;;
+#ml let mklib out files opts = Printf.sprintf "arm-linux-gnueabi-ar rc %s %s %s; arm-linux-gnueabi-ranlib %s" out opts files out;;
 
 ### Shared library support
 # Extension for shared libraries: so if supported, a if not supported
diff --git x86_64-to-arm/inria/ocaml-3.12.0/otherlibs/systhreads/Makefile x86_64-to-arm/inria/ocaml-3.12.0/otherlibs/systhreads/Makefile
index 454e33d..2812109 100644
--- x86_64-to-arm/inria/ocaml-3.12.0/otherlibs/systhreads/Makefile
+++ x86_64-to-arm/inria/ocaml-3.12.0/otherlibs/systhreads/Makefile
@@ -82,6 +82,7 @@ install:
 installopt:
    cp libthreadsnat.a $(LIBDIR)/libthreadsnat.a
    cd $(LIBDIR); $(TARGET_RANLIB) libthreadsnat.a
+   if test -d $(LIBDIR)/threads; then :; else mkdir $(LIBDIR)/threads; fi
    cp $(THREAD_OBJS:.cmo=.cmx) threads.cmxa threads.a $(LIBDIR)/threads
    cd $(LIBDIR)/threads; $(TARGET_RANLIB) threads.a

_________________
Download | Report bugs | git mirror
Back to top
View user's profile Send private message Visit poster's website
ygrek
professional


Joined: 20 Mar 2010
Posts: 610

PostPosted: Sat Apr 02, 2011 1:31 pm    Post subject: Reply with quote

BTW, have you seen http://www.func.cz.cc/2010/12/ocaml-cross-compiler-pt-ii.html (in russian)? IIUC it is based on inria patch.
_________________
Download | Report bugs | git mirror
Back to top
View user's profile Send private message Visit poster's website
ygrek
professional


Joined: 20 Mar 2010
Posts: 610

PostPosted: Sat Apr 02, 2011 10:14 pm    Post subject: Reply with quote

I have successfully compiled mldonkey with ocaml armel cross compiler and verified that it works in armel qemu.

System setup : default ocaml 3.11.2, ocaml 3.12.0 in /opt/ocaml-3.12.0, cross compiler in /opt/ocaml-3.12.0-wagle-armel-cross (with above patch), arm-linux-gnueabi- toolchain and zlib from emdebian repo. In order to shadow system ocaml installation I put 3.12.0 in PATH. Also need to copy caml include headers into cross-compiler LIBDIR with the following script (extracted from ocaml's build/install.sh) after cross compiler is built :
Code:

set -e
LIBDIR=/opt/ocaml-3.12.0-wagle-armel-cross/lib/ocaml
mkdir -p $LIBDIR/caml

PUBLIC_INCLUDES="\
  alloc.h callback.h config.h custom.h fail.h intext.h \
  memory.h misc.h mlvalues.h printexc.h signals.h compatibility.h"

cd byterun
for i in $PUBLIC_INCLUDES; do
  echo "  install caml/$i"
  sed -f ../tools/cleanup-header $i > $LIBDIR/caml/$i
done
cd ..


Now to mldonkey build. configure script will fail to detect GNU C library version - this is expected. GD is disabled explicitely cause otherwise it picks gdlib-config from PATH and puts /usr/include in CFLAGS and breaks things.
Apply the patch :
Code:

diff --git config/Makefile.config.in config/Makefile.config.in
index cbf74a8..f70bbce 100644
--- config/Makefile.config.in
+++ config/Makefile.config.in
@@ -12,6 +12,7 @@ CONFIG_INCLUDES=@CONFIG_INCLUDES@
 OCAMLC=@OCAMLC@
 OCAMLLIB=@OCAMLLIB@
 OCAMLOPT=@OCAMLOPT@ -inline 10
+OCAMLBEST=@OCAMLBEST@
 OCAMLLEX=@OCAMLLEX@
 OCAMLDEP=@OCAMLDEP@ @OCAMLDEP_OPTIONS@
 OCAMLDEP_OPTIONS=@OCAMLDEP_OPTIONS@
diff --git config/Makefile.in config/Makefile.in
index ef4e243..64eca7e 100644
--- config/Makefile.in
+++ config/Makefile.in
@@ -1434,10 +1434,10 @@ ocamldoc_html: $(CORE_DOC) $(libclient_DOC)
    $(OCAMLDOC) -sort -dump ocamldoc/ocamldocdump -html -d ocamldoc $(INCLUDES) $(libclient_DOC) $(CORE_DOC)
 
 $(LIB)/md4_cc.o: $(LIB)/md4.c
-   $(OCAMLC) -ccopt "$(CFLAGS) -O6 -o $(LIB)/md4_cc.o" -ccopt "" -c $(LIB)/md4.c
+   $(OCAMLBEST) -ccopt "$(CFLAGS) -O6 -o $(LIB)/md4_cc.o" -ccopt "" -c $(LIB)/md4.c
 
 $(CDK)/heap_c.o: $(CDK)/heap_c.c
-   $(OCAMLC) -ccopt "$(CFLAGS) $(MORECFLAGS) -o $(CDK)/heap_c.o" -ccopt "" -c $(CDK)/heap_c.c
+   $(OCAMLBEST) -ccopt "$(CFLAGS) $(MORECFLAGS) -o $(CDK)/heap_c.o" -ccopt "" -c $(CDK)/heap_c.c
 
 $(LIB)/md4_as.o: $(LIB)/md4_$(MD4ARCH).s
    as -o $(LIB)/md4_as.o $(LIB)/md4_$(MD4ARCH).s
@@ -1876,7 +1876,7 @@ rpm: sourcedist
    @$(OCAMLPP) -pp $< > $@
 
 .c.o :
-   $(OCAMLC) -verbose -ccopt "-I $(OCAML_SRC)/byterun -o $*.o" -ccopt "$(CFLAGS)" $(LIBS_flags) -c $<
+   $(OCAMLBEST) -verbose -ccopt "-I $(OCAML_SRC)/byterun -o $*.o" -ccopt "$(CFLAGS)" $(LIBS_flags) -c $<
 
 .cc.o :
    $(CXX) $(CXXFLAGS) $(CRYPTOPPFLAGS) -o $*.o "-I$(OCAMLLIB)" -c $<
diff --git config/configure.in config/configure.in
index 82dbe72..9182813 100644
--- config/configure.in
+++ config/configure.in
@@ -712,6 +712,12 @@ if test "$DEBUG" = "yes"; then
     OCAMLOPT="$OCAMLOPT -g"
 fi
 
+if test "$TARGET_TYPE" = "byte"; then
+    OCAMLBEST="$OCAMLC"
+else
+    OCAMLBEST="$OCAMLOPT"
+fi
+
 echo -e "\n----------------------------------"
 echo "     Checking system headers."
 echo "----------------------------------"
@@ -1419,6 +1425,7 @@ AC_SUBST(CONFIG_INCLUDES)
 AC_SUBST(OCAMLC)
 AC_SUBST(OCAMLLIB)
 AC_SUBST(OCAMLOPT)
+AC_SUBST(OCAMLBEST)
 AC_SUBST(OCAMLLEX)
 AC_SUBST(OCAMLYACC)
 AC_SUBST(OCAMLDEP)

Build :
Code:

PATH=/opt/ocaml-3.12.0/bin:$PATH ./configure --enable-debug OCAMLOPT=/opt/ocaml-3.12.0-wagle-armel-cross/bin/ocamlopt --host=arm-linux-gnueabi --disable-gd
echo DEVFLAGS=-verbose >> config/Makefile.config
PATH=/opt/ocaml-3.12.0/bin:$PATH make

During build ranlib and ar are called (directly, not cross versions) but this doesn't seem to cause problems.

PS In order to cross-compile for bytecode-only archs (like MIPS) one would also need ocamlc bytecode cross-compiler or hack the C compiler invocation when building stubs..
_________________
Download | Report bugs | git mirror
Back to top
View user's profile Send private message Visit poster's website
ygrek
professional


Joined: 20 Mar 2010
Posts: 610

PostPosted: Sat Apr 02, 2011 10:27 pm    Post subject: Reply with quote

Code:

   --Buildinfo--
Version:    MLNet Multi-Network p2p client version 3.0.7
Networks:    Global Shares Fasttrack FileTP BitTorrent Donkey (SUI)
Ocaml version:    3.12.0 - C compiler version: 4.4.5 - C++ compiler version: 4.4.5
Built on:    Linux i686 2.6.32-5-686 (little endian)
Configure args:     '--enable-option-checking=fatal' '--enable-debug' 'OCAMLOPT=/opt/ocaml-3.12.0-wagle-armel-cross/bin/ocamlopt' '--host=arm-linux-gnueabi' '--disable-gd' 'host_alias=arm-linux-gnueabi'
Features:     threads zlib-1.2.3.3 no-bzip2 no-gd iconv(active) no-magic no-upnp no-natpmp no-check-bounds

   --Runinfo--
MLDonkey user:       admin (Warning: empty Password) - uptime: 0m 23s - running as hudson:hudson
Enabled nets:     Donkey BitTorrent FileTP
Server usage:    enabled
Geoip:       enabled, GeoLite data created by MaxMind, available from http://maxmind.com/
IP blocking:    no blocking list loaded
System info:    Linux debian-armel 2.6.26-1-versatile #1 Sun Mar 15 05:49:36 UTC 2009 armv5tejl
        language: EN - locale: UTF-8 - UTC offset: +0200
        max_string_length: 16777211 - word_size: 32 - max_array_length: 4194303 - max_int: 1073741823
        max file descriptors: 1024 - max useable file size: 2^63-1 bits (do the maths ;-p)

_________________
Download | Report bugs | git mirror
Back to top
View user's profile Send private message Visit poster's website
wagle
neophyte


Joined: 29 Mar 2011
Posts: 19

PostPosted: Tue Apr 05, 2011 5:49 am    Post subject: Reply with quote

By the way, your patches replace tabs with 4 spaces, above.

I'm fixing that in my repo.
Back to top
View user's profile Send private message
wagle
neophyte


Joined: 29 Mar 2011
Posts: 19

PostPosted: Tue Apr 05, 2011 6:45 am    Post subject: Reply with quote

ygrek wrote:
BTW, have you seen http://www.func.cz.cc/2010/12/ocaml-cross-compiler-pt-ii.html (in russian)? IIUC it is based on inria patch.


Google translate seems to get the Russian pretty well.

I will include it later this week. Thanks!
Back to top
View user's profile Send private message
wagle
neophyte


Joined: 29 Mar 2011
Posts: 19

PostPosted: Tue Apr 05, 2011 8:07 am    Post subject: Reply with quote

Oh darn, I'm having trouble. Can you put your repo up someplace (like github) so I can compare? Else my (bloated, sorry) mldonkey is at

https://github.com/wagle/mldonkey


Otherwise, I'm sleeping on it.
Back to top
View user's profile Send private message
ygrek
professional


Joined: 20 Mar 2010
Posts: 610

PostPosted: Tue Apr 05, 2011 8:22 am    Post subject: Reply with quote

Quote:
By the way, your patches replace tabs with 4 spaces, above.

Sorry for that, obviously forum is not the best medium to distribute patches for Makefiles :)
Quote:
Can you put your repo up someplace (like github) so I can compare?

There is a link to the repo in the signature to this post :)
http://repo.or.cz/w/mldonkey.git
_________________
Download | Report bugs | git mirror
Back to top
View user's profile Send private message Visit poster's website
wagle
neophyte


Joined: 29 Mar 2011
Posts: 19

PostPosted: Tue Apr 05, 2011 2:00 pm    Post subject: Reply with quote

I meant a repo with your mods in it. 8-D

For example, your patch is 8 lines off on one of the stock 3.0.7 files (but applies).
Back to top
View user's profile Send private message
ygrek
professional


Joined: 20 Mar 2010
Posts: 610

PostPosted: Tue Apr 05, 2011 2:18 pm    Post subject: Reply with quote

I didn't push this patch because it is not ideal - it will cause ocamlopt to be used for stubs when building byte target. Ideally there should be ocamlc cross compiler and then this patch is unnecessary.
_________________
Download | Report bugs | git mirror
Back to top
View user's profile Send private message Visit poster's website
wagle
neophyte


Joined: 29 Mar 2011
Posts: 19

PostPosted: Tue Apr 05, 2011 2:26 pm    Post subject: Reply with quote

Well, I want to see your patch work first hand, just so we are on the same page. If you think that mldonkey shouldn't have any patches, then that's what I will steer for. Its much easier to refactor when I go from working version to working version. As it is, your instructions didn't solve anything for me, hence my wondering what I did wrong.
Back to top
View user's profile Send private message
wagle
neophyte


Joined: 29 Mar 2011
Posts: 19

PostPosted: Tue Apr 05, 2011 2:28 pm    Post subject: Reply with quote

PS. You could start a (second) github (or whatever) repo just so you can throw it away when we are done.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    MLDonkey Forum Index -> Alternative platforms All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Sourceforge.net Logo