View Single Post
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#1
Me being a Fedora person, the Debian orientation of everything from playing with the device to developing for it kind of killed my initial enthusiasm. But, as soon as I changed perspective and saw this as a challenge to stitch together my own development environment on my Fedora machine without the use of scratchbox or Ubuntu VMware images, things got better.

The result is a working toolchain with an x86 compiler that generates ARM code. Since this set-up is not for the faint of heart, I won't go into all the details since I butchered some of the Debian package mechanics just to get things to work, but I hope someone might find this interesting and experiment without feeling the need to use something just because you're told to.

The base of everything is the rootstrap that's available for download. There is an x86 and an ARM version and I installed them on my Fedora machine and my N900 respectively. Just from this you can chroot to it and play around with a working compiler.

Code:
chroot /path/to/rootstrap /bin/sh
This lets you compile applications on your N900, just like that, and I soon had my first "Hello world!" written to the XTerminal.

The rootstrap is very basic and leaves you with a /.dev directory thats empty so you need to at least create /dev/null.

Code:
mkdir /dev
mknod /dev/null c 1 3
This is all that is needed to get apt-get to fire up and work in your chroot:ed haven. If you're a tad more adventurous you can always mount the real /dev into the haven, from outside.

Code:
mount --bind /dev /path/to/rootstrap/dev
So, the rootstrap on my Fedora machine has an x86 compiler that generates x86 code. No fun. This is fixed by downloading the toolchain that's used by the Maemo 5 SDK. Since this arrives in a debian package, and I wasn't too sure how I'd use it, I used deb2targz to get to the yummy stuff and poured that into the rootstrap.

Now I need the contents of /lib and /usr/lib from my N900 to be able to link my applications and this is just a matter or copying from the device to my machine. The headers needed to compile are easily installed using apt-get.

Finally, the trickiest part, is to get the toolchain with its compiler and linker to work inside the chroot:ed haven. I tinkered a bit, got some suggestions from people and ended up with these variables in my Makefile:

Code:
TOOLCHAIN = /scratchbox/compilers/cs2007q3-glibc2.5-arm7

CC = ${TOOLCHAIN}/bin/arm-none-linux-gnueabi-gcc
LD = ${TOOLCHAIN}/bin/arm-none-linux-gnueabi-ld

TOOLCHAIN_LIBC = ${TOOLCHAIN}/arm-none-linux-gnueabi/libc
TOOLCHAIN_OBJS = ${TOOLCHAIN_LIBC}/usr/lib/crt1.o  ${TOOLCHAIN_LIBC}/usr/lib/crti.o ${TOOLCHAIN_LIBC}/usr/lib/crtn.o

LD_FLAGS = --dynamic-linker=/lib/ld-linux.so.3
LD_FLAGS += ${TOOLCHAIN_OBJS} -l:${TOOLCHAIN_LIBC}/usr/lib/libc.so
After that it's just a matter of writing the code in your favourite editor, update your Makefile and use make to build. Yay!

I'm sure I've overlooked some important step but this is how I remember it. Most things are solved either with Google, the nice people in #maemo-devel or just being curious.
 

The Following 4 Users Say Thank You to Joorin For This Useful Post: