Solaris Cross Compiler

I have a Sun SPARCStation that runs Solaris. I need to install shftware on it, which includes some stuff that needs to be compiled with specific options or features. However, the sparc doesn’t have enough drive space in /, /usr, or /opt to install a compiler and all its related goodness. What is one to do?

That’s right: we need to make a cross compiler. I have a Linux box with more than enough drive space, so this is the natural option. Here’s a quick and dirty guide to making and using a cross compiler, using Red Hat Linux. However, this procedure can be adopted to any other platform.

We will need the following:

* binutils
* gcc
* Solaris headers/libraries

You can get the source for binutils and gcc online, but you’ll need access to a Solaris box (presumably the one you want to cross compile stuff for) to get copies of the headers and libraries. Sorry, but this stuff isn’t freely available online.

Grab the Solaris stuff into a tar file (the devel packages were installed on the Solaris box you’re doing this to, right?) with the following command:

$ tar -cf solarislibs.tar /lib /usr/lib /usr/include /usr/ccs/lib

Mine turned out to be around 24 megs gzipped. Copy this to your target machine. Now we need GCC and binutils. You will want to create a new directory to do all this work in; I created a directory called “solaris-cross-compiler” in my home to stuff everything into.

Grab the binutils source:

$ export CVSROOT=”:pserver:anoncvs@sources.redhat.com:/cvs/src”
$ cvs login
$ cvs -z3 co binutils

Once it’s done, grab the GCC source:

$ export CVS_RSH=”ssh”
$ export CVSROOT=”:ext:anoncvs@savannah.gnu.org:/cvsroot/gcc”
$ cvs -z3 co gcc

I used CVS, but you can get the source any way you see fit. Now that we have the source for binutils and gcc, and the tar file with the Solaris headers and libraries, we’re ready for some cross compiling action!

The binutils package needs to be built first: it has the assembler and stuff in it. Build it something like this:

$ cd src
$ ./configure –prefix=/usr/local/solaris8-cross-comp –target=sparc-sun-solaris2.8
$ make
$ make install

Assuming all went well, it’s time to install the Solaris libraries and headers to compile (and compile with) GCC.

$ cd /usr/local/solaris8-cross-comp
$ mkdir sysroot
$ cd sysroot
$ cp whatever/path/you/saves/it/to/solarislibs.tar.gz .
$ tar -xzf solarislibs.tar.gz

Now, go back to whatever dierctory you put the GCC sources and do the following:

$ mkdir gcc-build
$ cd gcc-build
$ export PATH=/usr/local/solaris8-cross-comp/bin:$PATH
$ ../gcc/configure –prefix=/usr/local/solaris8-cross-comp –target=sparc-sun-solaris2.8 –with-gnu-as –with-gnu-ld –with-sysroot=/usr/local/solaris8-cross-comp/sysroot –enable-languages=c,c++,objc
$ make

$make install