Re: [Mono-list] Cross compiling mono 2.4 to PowerPC

2009-07-06 Thread Dushara Jayasinghe
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-boun...@lists.ximian.com [mailto:mono-list-
> boun...@lists.ximian.com] On Behalf Of Dushara Jayasinghe
> Sent: Monday, 29 June 2009 10:20 AM
> To: 'andreas.faer...@web.de'
> Cc: 'mono-list@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

Re: [Mono-list] Problems compiling Mono 2.4.2

2009-07-05 Thread Dushara Jayasinghe
Just curious, don't you need root access to do make install?

d

> -Original Message-
> From: mono-list-boun...@lists.ximian.com [mailto:mono-list-
> boun...@lists.ximian.com] On Behalf Of Daniel Isenmann
> Sent: Sunday, 5 July 2009 10:09 PM
> To: Mono-list@lists.ximian.com
> Subject: [Mono-list] Problems compiling Mono 2.4.2
> 
> Hi,
> 
> I have problems compiling mono 2.4.2. The compilation process went
> through without problems, but the "make install" command prints out
> following error:
> 
> ---
> 
> Making install in metadata
> make[2]: Entering directory
> `/home/ise/svn-packages/mono/trunk/src/mono-2.4.2/mono/metadata'
> make[3]: Entering directory
> `/home/ise/svn-packages/mono/trunk/src/mono-2.4.2/mono/metadata' test
> -z "/usr/bin" || /bin/mkdir -p
> "/home/ise/svn-packages/mono/trunk/pkg/usr/bin" ../../doltlibtool
> --quiet   --mode=install /bin/install -c pedump
> '/home/ise/svn-packages/mono/trunk/pkg/usr/bin' test -z
> "/usr/include/mono-1.0/mono/metadata" || /bin/mkdir -p
> "/home/ise/svn-packages/mono/trunk/pkg/usr/include/mono-
> 1.0/mono/metadata" /bin/install
> -c -m 644 attrdefs.h appdomain.h mono-debug.h mono-gc.h
> debug-mono-symfile.h threads.h environment.h assembly.h opcodes.h
> blob.h image.h metadata.h verify.h reflection.h row-indexes.h
> tokentype.h loader.h class.h object.h exception.h profiler.h
> appdomain.h mono-config.h debug-helpers.h mempool.h
> '/home/ise/svn-packages/mono/trunk/pkg/usr/include/mono-
> 1.0/mono/metadata' /bin/install:
> will not overwrite just-created
> `/home/ise/svn-packages/mono/trunk/pkg/usr/include/mono-
> 1.0/mono/metadata/appdomain.h'
> with `appdomain.h' make[3]: *** [install-libmonoruntimeincludeHEADERS]
> Error 1 make[3]: Leaving directory
> `/home/ise/svn-packages/mono/trunk/src/mono-2.4.2/mono/metadata'
> make[2]: *** [install-am] Error 2 make[2]: Leaving directory
> `/home/ise/svn-packages/mono/trunk/src/mono-2.4.2/mono/metadata'
> make[1]: *** [install-recursive] Error 1 make[1]: Leaving directory
> `/home/ise/svn-packages/mono/trunk/src/mono-2.4.2/mono' make: ***
> [install-recursive] Error 1
> 
> 
> 
> I'm compiling with the following flags:
> 
> ./configure --prefix=/usr --sysconfdir=/etc \
>   --with-libgdiplus=installed --with-icu=no \
>   --with-tls=pthread --with-jit=yes --with-preview=yes \
>   --with-sigaltstack=yes --enable-nunit-tests \
> --with-moonlight=yes
>   make || return 1
>   make install
> 
> 
> It worked in version 2.4 without problems. Compiling everything with
> gcc-4.4.0 on ArchLinux x86_64.
> 
> Any hints?
> 
> Thanks,
>  Daniel
> ___
> Mono-list maillist  -  Mono-list@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
> __
___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] Cross compiling mono 2.4 to PowerPC

2009-06-28 Thread Dushara Jayasinghe
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@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


[Mono-list] FW: Cross compiling mono 2.4 to PowerPC

2009-06-25 Thread Dushara Jayasinghe
> On 25-Jun-09, at 12:38 AM, Dushara Jayasinghe wrote:
> 
> >> You should update to the tip of the 2.4 branch or head which fixes
> >> this (among other) problem.
> >>
> >
> > I'm using the official source distribution @
> http://ftp.novell.com/pub/mono/sources-stable/
> >
> > Anyway, I've got the build itself working or do you believe that the
> > original problem I highlighted (The file /usr/lib/mscorlib.dll is an
> > invalid CIL image) is related to the build system itself?
> >
> 
> Yes, this is 99% the case, you have a brkoen build.

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).

My original problem still remains. As I mentioned earlier I'm performing a 
cross compile. There's no building taking place in the target (PowerPC) 
platform.

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?

Thanks again

Dushara

___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] Cross compiling mono 2.4 to PowerPC

2009-06-24 Thread Dushara Jayasinghe
> You should update to the tip of the 2.4 branch or head which fixes
> this (among other) problem.
> 

I'm using the official source distribution @ 
http://ftp.novell.com/pub/mono/sources-stable/

Anyway, I've got the build itself working or do you believe that the original 
problem I highlighted (The file /usr/lib/mscorlib.dll is an invalid CIL image) 
is related to the build system itself?

As I mentioned earlier, the mono binary is successfully built. I can execute it 
on the target platform. I _have_ deviated from the traditional build approach 
by using cross tools instead of building in the target itself but I fail to see 
how that should cause any issues.

Thanks again for you assistance.

Dushara


> -g
> 
> __
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> __
___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] Cross compiling mono 2.4 to PowerPC

2009-06-23 Thread Dushara Jayasinghe
> > That would likely save you a lot of pain rather than configure
> hacking.
> >
> >
> 
> I remember I got compile time errors when I tried it last (it was
> trying to build some libraries still). That's why I had to resort to
> the configure hack. I'll check again to verify though.
> 

These are the errors I was getting:

./configure --prefix=/usr --with-sigaltstack=no  --with-tls=__thread 
--disable-mcs-build --host=ppc-linux

Resulted in the following error:
...
checking for working __thread... configure: error: cannot run test program 
while cross compiling

After configure.in was hacked, 'make' gave the following error:

...
make[2]: Entering directory `/home/cis2/mono-2.4/docs'
cd . && make -f docs.make topdir=../mcs convert.exe
make[3]: Entering directory `/home/cis2/mono-2.4/docs'
MCS [net_2_0] convert.exe
make[3]: *** [convert.exe] Error 1

So I had to hack Makefile.am to get rid of docs from the list of subdirectories.

Dushara

___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] Cross compiling mono 2.4 to PowerPC

2009-06-23 Thread Dushara Jayasinghe
Thanks for the quick reply.

> > 1. Modified Configure.in Makefile.am to avoid compiling the
> > libraries when in cross compile mode. - I needed this step because,
> > the build system attempts to build libraries using mono itself.
> >
> > 2. Compiled the binaries for the target system.
> 
> Have you looked at the configure options for step 1&2, specifically --
> disable-mcs-build for cross compiling?
> 
> That would likely save you a lot of pain rather than configure hacking.
> 
> 

I remember I got compile time errors when I tried it last (it was trying to 
build some libraries still). That's why I had to resort to the configure hack. 
I'll check again to verify though.

Dushara

___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


[Mono-list] Cross compiling mono 2.4 to PowerPC

2009-06-23 Thread Dushara Jayasinghe
Hi

I'm trying to cross compile mono 2.4 embedded PowerPC based system. For a 
couple of reasons, I'm trying to avoid building mono in the target itself. 
These are the steps I took:

1. Modified Configure.in Makefile.am to avoid compiling the libraries when in 
cross compile mode. - I needed this step because, the build system attempts to 
build libraries using mono itself.

2. Compiled the binaries for the target system.

3. Compiled mono for for the host system.

4. Copied the mono binary (built in step 2) and mscorlib.dll (built in step 3) 
to the target system.

However, when I try to execute a mono app, I get the following error:

The file /usr/lib/mscorlib.dll is an invalid CIL image

Does the DLL in question contain native code? If not, is there any way I can 
overcome this problem?

Thanks
Dushara
___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list