In building the CLFS PowerPC cross compiler the instructions say to create both the /tools and /cross-tools directories (these are actually symlinks to directories of your choosing but it's the easiest way to reference what I'm talking about).  I didn't fully understand why this is the case so I did some Googling and re-read parts of the CLFS book.

Turns out it's briefly described across various sections, including: 4.2 (Creating the /tools Directory), 4.3 (Creating the /cross-tools Directory), 5.4 (Linux-Headers), and 6.1 (Introduction to chapter 6).

The /cross-tools directory is where the actual cross compiler and its assorted "friends" will live.  The /tools directory is where we're building a temporary system that can actually build a real system.  The entire goal of chapter 5 is to build a GCC cross compiler that executes on your desktop PC and builds executables for some other computer system (in my case, my desktop's an x86_64 box running Debian Lenny and I'm wanting to create executables for PowerPC Linux).

A fun problem is that in order to build a cross compiler, we need a compiler (and a bunch of other stuff).  There may be a shorter method to achieving this, but I outline the CLFS way of doing things:
  • Starting off with section 5.4 (Linux Headers), just the header files for a Linux kernel are installed into /tools/include.  The headers will be needed later to build Glibc.   
  • In section 5.5 (File), we build and install File into /cross-tools (File lets us figure out what type any given file is).  This version of File we build is a native application on our desktop PC and is used by other steps.
  • Section 5.6 (Cross Binutils) has us build a set of binutils, again these are native to our desktop PC.  No cross compiling yet.  Binutils assists in compiling and linking programs.  We'll use this set of binutils to build our cross compiler, GCC.  Binutils gets installed into /cross-tools.
  • Now we get to some compiler compiling, section 5.7 (Cross GCC - Static).  Here we build a very simple, statically linked version (it includes all libraries it needs internally to itself rather than reference them being installed in another location) of GCC that can only compile C programs.  GCC is actually built without any C library (Glibc) as we don't yet have it.  GCC goes into /cross-tools.
  • Section 5.8 (Glibc) finally gets us to the C library.  When configuring Glibc, we must tell the configuration script how to find all the different items we've already installed, as they're in non-standard locations.  Glibc gets built using our statically linked GCC and our kernel headers, it has just enough ability to do so, and installed into the /tools directory.  The kernel headers are needed as some of the implementation of the C library involves making system calls, thus the C library needs to know how to make those system calls.
  • Now we can finally create an actual cross compiler.  Section 5.9 (Cross GCC - Final) finally has us build a real C and C++ cross compiler.  This step uses the previously built statically linked GCC and Glibc to create a real, dynamically linked, version of GCC.  Now we have a cross compiler!

I'm curious to see how much of what was used to build our cross compiler is still needed in order to complete the CLFS book.  Maybe this is a job for git (another thing I'd like to learn).



09 November 2010