Documentation/Setting-up-gcc : quickie guide to setting up the C compiler
Copyright (c) 2005-2007 Garth Zeglin

This file is part of ArtLPC, distributed under the terms of
the GNU General Public License version 2 or later.

/****************************************************************/

Following are notes I took while compiling gcc 3.4.4 to cross-compile
ARM7 code for LPC2xxx chips.  This works the same under OS X and
Linux, and probably any other platform supported by gcc.

For the time being, it is recommended to stick with the identical
3.4.4 compiler revision.  The compiler is used to generate interrupt
routines, which introduces some sensitivity to the specific version.
For example, gcc 3.3 will not generate correct interrupt entry
sequences for the ArtLPC code.  At the least, no guarantees about the
existing codebase are made if you use a newer compiler.

This is best intended as a rough guide; the specifics can vary with
your installation, so the gcc and binutils documentation should be
considered definitive.

This process produces a C compiler without C++.  ArtLPC doesn't need
C++, so when I had some problems configuring gcc for C++ I didn't try
hard at getting it to work.  Since the gnude project distributes an
ARM7 cross-compiler with C++, it is clearly possible.  At the time of
writing, the gcc version bundled with gnude was too old for ArtLPC to
compile correctly, but perhaps newer versions might be an easy way to
get a ready-to-go compiler.

Note for those really new to this: cross-compiling means generating a
runnable program from source code using a computer other than the
ultimate destination.  For example, using your OS X machine to create
a .hex object file from the source code.  The .hex file is what is
then downloaded into the LPC2xxx chip to run.

================================================================

The first step is to set up a cross-compiling binutils.  This package
includes the assembler, linker, and various object file tools.

1. compiling binutils for arm-elf under Linux
   [download http://ftp.gnu.org/gnu/binutils/binutils-2.16.tar.bz2]

   [unpack binutils-2.16.tar.bz2]
   tar xjvf binutils-2.16.tar.bz2

   [compile and install into /usr/local/arm]
   ./configure --prefix=/usr/local/arm --target=arm-elf
   make
   make install

2. compiling the gcc C compiler as an arm-elf cross-compiler under Linux

  [download http://mirrors.rcn.net/pub/sourceware/gcc/releases/gcc-3.4.4/gcc-3.4.4.tar.bz2]

  [unpack gcc-3.4.4.tar.bz2]
  tar xjvf gcc-3.4.4.tar.bz2

  [create a separate directory for the compiled files]
  mkdir gcc-3.4.4-obj

  [build the compiler in the new directory and install it]
  cd gcc-3.4.4-obj
  ../gcc-3.4.4/configure --prefix=/usr/local/arm  --target=arm-elf --with-cpu=arm7tdmi --enable-languages=c --without-headers

  make
  make install

3. adding the tools to your path

This instruction is highly dependent on your particular system.  On my
machine, I added the following lines to my .profile file in my home
directory:

# for my local ARM cross-compiler
export PATH="$PATH:/usr/local/arm/bin"
export MANPATH="$MANPATH:/usr/local/arm/man"

4. testing the tools

If all went well, then arm-elf-gcc should be available from the command line:

  $ arm-elf-gcc --version
  arm-elf-gcc (GCC) 3.4.4
  Copyright (C) 2004 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

It should then be possible to compile the ArtLPC code by running "make"
in the top-level directory of the distribution; see the Quickstart
file for more.
