[Nix-dev] cross compiling with Nix

Armijn Hemel armijn at uulug.nl
Sat Nov 5 00:59:11 CET 2005


hi all,

I managed to get a very rudimentary cross-compiler working. That is, I
built a cross-binutils and a cross-GCC (C only) in Nix. It took some time to
figure out how that all worked (well, not cross-binutils, that's beyond
easy). Why? Because I'm getting fed up with the current Linux install on
my HP Jornada and I need something new. The last time I built for that
machine was rather painful: juggling with the right headers, the right
PATHs, etcetera.

Anyway, I managed to compile uClibc with it, outside of Nix. Why outside?
Well, because the gcc-wrapper scripts are pretty much glibc and native
compiler specific. Right now even the "gcc" link doesn't work, because
a cross compiler is by default not called gcc, but something like
arm-linux-gcc. I still need to find a way to deal with all this, but I
might even partly chuck the whole gcc-wrapper for building a cross
compiler. Some results:

$ file libuClibc-0.9.28.so
libuClibc-0.9.28.so: ELF 32-bit LSB shared object, ARM, version 1 (ARM), stripped

I added the cross gcc and cross binutils to my $PATH:

$ which arm-linux-gcc
/nix/store/fjpr3m0wzij2ykj5g9csng6x41r2nbs4-gcc-4.0.2-arm/bin/arm-linux-gcc

In the configuration for uClibc I set one thing, namely the header files for
the platform:

KERNEL_SOURCE="/nix/store/ly27c9qabzp6v8jc8nwlhkw69fdbdzmh-linux-headers-2.6.13.4-arm"

and then did a "make CROSS=arm-linux-" (including the last hyphen) and it
built everything. Of course, this is not completely pure and more time needs
to be put into that to make it work correctly.

I think this would be a great application area for Nix. Companies that make
embedded software often need to have a fixed environment for development for
various devices/firmware revisions/whatever. With Nix it can't really go
"suddenly wrong". It would be a great selling point. Also, upgrading a compiler
and rebuilding everything won't mean you have to juggle with PATH settings
anymore.

I won't commit yet, because it's still not ready (unless others want to
improve upon it, then I will). There is a lot of room for improvement.
Right now I've hardcoded "arm-linux" in some files, but this should be
parameterized, so we can also build for mips, mipsel, sparc, etc.

If anyone wants to help, I've got a spare Jornada at the lab which can be
used, but bring your own CompactFlash card (EUR 23 or so for 256 MB if you
don't have one yet) :)

armijn

-- 
 ---------------------------------------------------------------------------
  armijn at uulug.nl | http://www.uulug.nl/ | UULug: Utrecht Linux Users Group
 ---------------------------------------------------------------------------



More information about the nix-dev mailing list