[Mono-list] Cross compiling mono 2.4 to PowerPC

Dushara Jayasinghe DusharaJ at optiscan.com
Mon Jul 6 23:05:39 EDT 2009


SOLVED

I will write this as a quick HOWTO in the hope that others may find it useful. If there are any mistakes, omissions or inefficiencies, please let me know. There are attachments in this email, I hope I'm not breaking any ML rules.

HOWTO cross-compile mono (2.4) for a PPC target.

1. Introduction

My goal was to compile mono for an MPC8349 based system using the tool-chain provided by the Embedded Linux Development Kit (ELDK). I wanted to use a cross compiler (as opposed to building on the target platform itself) for 2 reasons:

1. The build itself will take too long
2. More importantly, it simplifies our automated build system

Furthermore, I had to use the mono-2.4 branch because that's what our App developers were using.

2. Used tools/packages

* ELDK 4.2  (http://www.denx.de/wiki/DULG/ELDK)
* Linux from scratch LiveCD (http://www.linuxfromscratch.org/livecd/download.html)
* mono-2.4.2 (http://ftp.novell.com/pub/mono/sources/mono/)
* glib-2.4 (http://ftp.gnome.org/pub/gnome/sources/glib/2.4/)

As in the case of the ARM port(http://www.mono-project.com/Mono:ARM), we use a 2-stage build. The first stage to build the libraries and the 2nd to build the target specific binaries. This presents an interesting problem: The location of glib must be the same in both stages. However each stage requires a target specific build/headers of glib. In other words, we need to overwrite the system installed version with a cross-compiled version of glib. I worked around this problem by using a chroot environment.

3. Preparing the build environment

~/src/iso/$ mkdir build
~/src/iso/$ sudo mount -o loop lfslivecd-x86-6.3-min-r2052.iso build
~/src/iso/$ cp build/root.ext2 .
~/src/iso/$ sudo umount build
~/src/iso/$ sudo mount -o loop root.ext2 build

Tweak the fs

~/src/iso/$ sudo chroot build
bash-3.2# mkdir /opt/eldk
bash-3.2# rm -rf /home/jhalfs/jhalfs-2.3.1

Add/change the following lines in /etc/profile

	PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/eldk/usr/bin
	CROSS_COMPILE=ppc_6xx-		<--- change to suit
	ARCH=powerpc
	export CROSS_COMPILE ARCH

bash-3.2# exit

Package env for later use

~/src/iso/$ sudo tar -cjf build.tar.bz2 build
~/src/iso/$ sudo umount build
~/src/iso/$ rm root.ext2

4. Building mono
4.1. Setting up and entering the build environment

~/src/iso/$ sudo tar -xjf build.tar.bz2
~/src/iso/$ sudo ln mono-2.4.2.tar.bz2 build/home/jhalfs/
~/src/iso/$ sudo ln glib-2.4.0.tar.bz2 build/home/jhalfs/
~/src/iso/$ sudo cp glib.cache mono-2.4-cis2.patch build/home/jhalfs/
~/src/iso/$ sudo mount -o bind /opt/eldk42 build/opt/eldk
~/src/iso/$ sudo chroot build
bash-3.2# mount /proc
bash-3.2# su - jhalfs

4.2. Build Stage 1
epmdev3:jhalfs | Tue Jul  7 01:48:15 2009 | ~
$ tar -xjf glib-2.4.0.tar.bz2
$ tar -xjf mono-2.4.2.tar.bz2
$ cd mono-2.4.2 
$ ./configure --prefix=/usr
$ make
$ sudo make install
$ make DESTDIR=$HOME/install install

4.3. Build Stage 2
$ cd ../glib-2.4.0
$ ./configure --cache-file=../glib.cache --prefix=/usr \
	--bindir=`pwd`/../junk --host=ppc-linux

NOTE: you can use the glib.cache attached with this email, or make one that suits your system.

$ make
$ make DESTDIR=$HOME/install install
$ cd ../mono-2.4.2 
$ make clean
$ patch -p1 <../mono-2.4-cis2.patch

NOTE: This patch above is a rough hack which fixes the following 2 problems:

1. The configure script fails because it tries to execute some target specific code
2. The make breaks because it tries to build the docs directory. A mono binary is used to build the contents of docs and since we are cross compiling, the tool fails. If you're using the sources from the SVN/Trunk, you don't need to do this because there's a configure option to disable the docs build.

$ autoreconf --install --force
$ ./configure --prefix=/ \
                --cache-file=cis2.cache --host=ppc-linux \
                --with-tls=__thread --disable-mcs-build \
                --with-sigaltstack=no
$ make
$ make DESTDIR=$HOME/install install

Now you should have a working cross-build of mono in $HOME/install. Copy the contents (or what you need) to your target platform.


Dushara

> -----Original Message-----
> From: mono-list-bounces at lists.ximian.com [mailto:mono-list-
> bounces at lists.ximian.com] On Behalf Of Dushara Jayasinghe
> Sent: Monday, 29 June 2009 10:20 AM
> To: 'andreas.faerber at web.de'
> Cc: 'mono-list at lists.ximian.com'
> Subject: Re: [Mono-list] Cross compiling mono 2.4 to PowerPC
> 
> Hi Andreas, thanks for the response.
> 
> > > I tried version 2.4.2-rc1 (http://anonsvn.mono-
> > project.com/viewvc/tags/mono-2-4-2-rc1/
> > > ). I still had to tweak configure.in:
> > >
> > > checking for working __thread... configure: error: cannot run test
> > > program while cross compiling
> > >
> > > and Makefile.am (build breaks after entering the docs subdir).
> >
> > Did you read `./configure -h` output? ...
> 
> Yes
> 
> > ... There's not only the --disable-
> > mcs-build option but also --with-mcs-docs=no. That should in theory
> > take care of the latter, without any Makefile modification.
> 
> The option --with-mcs-docs doesn't exist in the version I'm using.
> Maybe I need to look at a later version then (perhaps rc2)? The reason
> I didn't checkout the tip was because of the comment in the download
> page stating that the daily SVN tarballs are not guaranteed to build.
> 
> >
> > For the other one, there's --with-tls=__thread or --with-tls=pthread.
> > Please read for yourself.
> 
> I invoke configure as
> 
> ./configure --prefix=/usr --cache-file=cis2.cache --with-sigaltstack=no
> --with-tls=__thread --disable-mcs-build --host=ppc-linux
> 
> I still get the error. That's why I had to hack configure.in to add a
> caching variable 'mono_cv_workingthread'.
> 
> > > The mono:arm page (http://www.mono-project.com/Mono:ARM) recommends
> > > using scratchbox. Does this mean that mono can't be built using
> > > cross compilers?
> >
> > It can, it's just not for the feint-hearted and not well documented.
> > You need to understand autoconf and you may need to know details of
> > the target platform.
> 
> Well at least now I know that it's possible. Thanks.
> 
> Now if I may assume that I've got the build working properly, I wonder
> if anyone could provide any clues as to why mscorlib.dll is rejected?
> On the x86 dev environment the DLL is parsed properly by pedump. On the
> target (the PPC), the same DLL is rejected. Could the endienness of the
> 2 architectures be causing some sort of problem?
> 
> Thanks again for all your help.
> 
> Dushara
> 
> 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mono-2.4-cis2.patch
Type: application/octet-stream
Size: 4465 bytes
Desc: mono-2.4-cis2.patch
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20090707/014f86dc/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glib.cache
Type: application/octet-stream
Size: 74 bytes
Desc: glib.cache
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20090707/014f86dc/attachment-0001.obj 


More information about the Mono-list mailing list