Halaman

Selasa, 07 Januari 2014

[c++, c#] Journey of cross compiling mono 3.2.5, utilizing ScratchBox2

This one is a tough one, usually i get away compiling just by trial-and-error after successfully compiling the library for the windows target. But compiling this one is very much a challenge.. and then out of curiosity.. here i am writing this blog entry so that someday i could revisit and think .. what the **** am i doing compiling libraries and not doing those projects!

Well if my future me see this post, "I do it because of cross environment, playbook, win 7.5, vala, mono, xna, cocos2dxna, and Pou.. i bet you will understand and remember.. hehe, and yes, i know, it is very silly.. but Y.O.L.O!"

So let's go with it shall we..

After trying to compile using BB NDK SDK version 2.1 i encountered problem with the assembler compilation. If i can recall the error correctly, the message was "invalid operation $03" or something similar like that..

After 2 nights of blackened eyes, i give up and then tried to compile on a virtual machine, for that machine i choose LINUX Mint 15 for the OS, chosen simply because the OS iso file lying around on my hard-disk. For the virtualization, i'm using vmware

I was thinking about using linux because i could simply use ./configure and then make, but i think to myself it would be better if i could directly compile this for the arm architecture, after diving to google, there is a very exciting project callled Scratchbox2, and then here i am using the command

$ sudo apt-get install scratchbox2
$ sudo apt-get install qemu

Then i tried to find linux arm compiler toolchain, for this purpose i search for the file arm2009q1-203-none-linux-gnueabi simply because that is the compiler i used in Windows when venturing with WebOS.. (love that platform.. hixs..)

here is the name of the file i downloaded from codesourcery: arm-2009q1-203-arm-none-linux-gnueabi.bin

What?? you need the web address you say? here it is: http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/

Let's go to the terminal and then type the following..

$ chmod +x arm2009*
$ ./arm2009*

Follow those installation screen with care, i choose to install on default directory.. and that is at $HOME/CodeSourcery

Here is the trick! if i use sb2-init with the -c and without -C -static it will fail to run sb2-build-libtool! don't know about that -c, but if i did not specify -C -static, the compiled will try to find the library linux.so.3, about the -lpthread, that's because when compiling mono, there are undefined references to pthread, so i decided to put that to default.. maybe we should find a cleaner solution to this

Therefore here is the command i use to initialize sb2

$ sb2-init -d -C "-static -lpthread" arm $HOME/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc

$ sb2-init -d arm $HOME/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc

when not using this arm-2009q1-203-arm-none-linux-gnueabi.bin release, for example using built in arm-linux-gnuebi-gcc (from the apt), i failed to run sb2-build-libtool, a workaround would be adding parameter -C "-static" to sb2-init but i guess this would break some build system.. note to self: Need to find-out building custom rootfs! (finger crossed, perhaps copying the libc content? hehe..)

important! you need to init sb2 in $HOME/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc because that is the rootfs for that toolchain

let's try with a simple hello world program shall we..

$ sb2
$ gcc hello.cpp -o hello
$ file hello --> this should show that we have compiled for the arm-architecture! ;)
$ ./hello --> will run!
$ exit ->> this will exit us from the "jail" arm-environment we had setup earlier

Ok, now is the fun part, let's go to the extracted tarball mono source folder, cross your fingers :p and then type

$ sb2
$ ./configure --with-monotouch=no --without-mcs-docs --disable-mono-debugger CFLAGS="-DBROKEN_64BIT_ATOMICS_INTRINSIC -DARM_FPU_NONE" LIBS=-lpthread --disable-mcs-build

The configuration is a success!

But, the potential horror might now came along.. anyway.. let's proceed!

before make! i add the patch to the mono/mini/mini.arm.h
#define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
change that to
//#define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1

on the same terminal, lets go make some!

$ make
$ make install DESTDIR=$HOME/mymono

there you have it! a compiled mono for arm architecture!

Some hints:

for the mono's ./configure script, to show the options accepted by the configure run
$ ./configure --help

Ps. If you like and learn something from other people, and you can't or don't want to donate to them directly, show your support by sharing the article, google+ing the article, or perhaps checking out the advertisements which may appear on the website ;) many thanks before!







Tidak ada komentar:

Posting Komentar