Compiling and Installing the GNU Tools under Linux or Unix

Method 2: Individual Sources

This document shows you how to compile and install the GNU Tools for the ARM microcontroller under the Linux or Unix operating systems. Please note that it is much easier to install the precompiled binary image for Linux (as found on this CD-ROM). If you do choose to recompile the GNU Tools, as explained in this document, expect to spend about three hours doing so (depending, of course, on the speed of your machine).

There are three main methods of compiling the GNU Tools: by compiling a set of combined sources, by compiling the individual source directories (as described in this document), or by recreating the binary package. In general, the simplest of these three methods is the combined sources method: it tends to be less problematic, slightly faster and somewhat more convenient, as it involves less steps. The individual sources method, as described in this document, should only be used when the combined sources method fails (and that should be quite rare indeed). Recreating the binary package should be undertaken by system administrators wanting to retain complete control of their system… or those wanting to update this CD-ROM.

In this document, “$” will indicate the ordinary user’s shell prompt, and “#” will indicate the root superuser’s shell prompt. Anything in a bold monospaced font is what you are expected to type in; an ordinary monospaced font is used for the computer’s response. Please note that this document doesn’t show every response from the computer!

Minimum System Requirements

In order to successfully compile, install and run the GNU Tools, you will need to meet at least the following requirements:

1. A Linux, Unix or Unix-like operating system, with all of the usual utilities, system header files and libraries, as well as the X11 Window System (with header files and libraries), Perl, GNU gzip and bzip2,
2. An ANSI-compatible C compiler tool-set, such as the GNU Compiler Collection (gcc),
3. At least 850 MB of free disk space,
4. At least three hours of free time, and
5. The password to the root superuser’s account on your system.

Step-by-step Instructions

Compiling and installing the GNU Tools is not that complicated (although there are rather a lot of steps), but be careful that you type in the commands exactly as shown. These instructions assume that you have already mounted the CD-ROM on your computer, and that the mount point (where the CD-ROM can be found within the file system) is /mnt/cdrom. See the instructions for mounting the CD-ROM for more details.

1. Log in as an ordinary user, not as the root superuser. This is highly recommended and is standard Unix practice. In fact, you should never directly log in as the root superuser; this helps save you from your own mistakes and/or any viruses that can destroy the working of your system!
2. Create a directory to contain the sources. Note that at least 740 MB of space is required for both the source code and build files. In this document, /var/tmp/src will be used for the sources:
mkdir /var/tmp/src
cd /var/tmp/src
3. Locate the appropriate sources, either on this CD-ROM, or by downloading the source code archives from the Internet. Assuming the CD-ROM is mounted on /mnt/cdrom, the source code archives can be found in [List] /mnt/cdrom/gnutools/src.
4. Unpack the sources:
gzip -dc /mnt/cdrom/gnutools/src/binutils-2.14.tar.gz | tar xv
gzip -dc /mnt/cdrom/gnutools/src/gcc-core-3.3.tar.gz | tar xv
gzip -dc /mnt/cdrom/gnutools/src/gcc-g++-3.3.tar.gz | tar xv
gzip -dc /mnt/cdrom/gnutools/src/insight-5.3.tar.gz | tar xv
gzip -dc /mnt/cdrom/gnutools/src/newlib-1.11.0.tar.gz | tar xv
If your version of tar is compatible with GNU tar, you can use tar xzvf ... instead of gzip -dc ... | tar xv: this will save a couple of minutes…
If you are using sources that you downloaded from the Internet, you would replace /mnt/cdrom/gnutools/src with the location of those sources, of course. Archives having .tar.gz on the end of their filename require GNU gzip; those with .tar.bz2 require bzip2.
5. Apply the appropriate patches (on this CD-ROM, or from the Internet) to the sources:
gzip -dc /mnt/cdrom/gnutools/src/binutils-2.14.patch.gz | patch -p0
gzip -dc /mnt/cdrom/gnutools/src/gcc-3.3.patch.gz | patch -p0
gzip -dc /mnt/cdrom/gnutools/src/insight-5.3.patch.gz | patch -p0
gzip -dc /mnt/cdrom/gnutools/src/newlib-1.11.0.patch.gz | patch -p0
Please note that parts of these patches may not need to be applied to later versions of the GNU Tools. You are on your own if you decide to use versions of software different from those described in this document! However, you might like to see if later versions of the patches exist on the Internet before giving up.
6. Create a separate directory, with subdirectories, in which to build the sources. In this document, /var/tmp/build will be used:
mkdir /var/tmp/build
cd /var/tmp/build
mkdir binutils-2.14 gcc-3.3 insight-5.3 newlib-1.11.0
7. Configure the binutils package:
cd /var/tmp/build/binutils-2.14
/var/tmp/src/binutils-2.14/configure --target=arm-elf
8. Compile the binutils package:
make all
9. As the root superuser, install the compiled binutils package. You will need the root superuser’s password:
/bin/su
make install
10. Still as the root superuser, create some destination directories and give everyone (temporary) write access to them:
cd /usr/local/arm-elf
mkdir sys-include
ln -s sys-include include
chmod g+w,o+w sys-include
cd /usr/local/lib
mkdir gcc-lib gcc-lib/arm-elf
chmod g+w,o+w gcc-lib/arm-elf
exit
11. Configure the gcc package:
cd /var/tmp/build/gcc-3.3
/var/tmp/src/gcc-3.3/configure --target=arm-elf --with-newlib --with-headers=/var/tmp/src/newlib-1.11.0/newlib/libc/include
12. Compile the gcc package:
make all
13. As the root superuser, install the compiled gcc package and remove the write permissions granted in step 10:
/bin/su
make install
cd /usr/local/arm-elf
rm -fr include sys-include
cd /usr/local/lib/gcc-lib/arm-elf
chown -R root:root .
chmod g-w,o-w .
exit
14. Configure the newlib package:
cd /var/tmp/build/newlib-1.11.0
/var/tmp/src/newlib-1.11.0/configure --target=arm-elf
15. Compile the newlib package:
make all
16. As the root superuser, install the compiled newlib package:
/bin/su
make install
exit
17. Configure insight. This package requires the X11 Window System header files and libraries:
cd /var/tmp/build/insight-5.3
/var/tmp/src/insight-5.3/configure --target=arm-elf
18. Compile the insight package:
make all
19. As the root superuser, install the compiled insight package:
/bin/su
make install
20. Still as the root superuser, clean up a number of installation issues and reduce the size of the final installation:
cd /usr/local/bin
strip arm-elf-*
cd /usr/local/lib/gcc-lib/arm-elf/3.3
strip cc1 cc1plus collect2 cpp0 tradcpp0
exit
21. (Optional) Remove the source code and build files to reclaim about 740 MB of disk space (the final binaries take about 110 MB of space):
cd /var/tmp
rm -fr src build
22. You have successfully compiled and installed the GNU Tools for the ARM microcontroller!

Common Problems

In most cases, you will not encounter any problems in compiling and installing the GNU Tools. There might be exceptions, however. You should check the following if a compilation (a “make all” step) terminates with an error:

Check that you entered all commands exactly as specified. Please note that your browser may split up commands over a number of lines (depending on the width of your browser window); that does not mean you do the same! Each shell prompt (“$” or “#”) indicates a single command line.

If all your efforts fail to get the GNU Tools compiled and installed (and you have tried and failed with the combined sources method), either install the precompiled binary image, search the Internet for answers or consult your local Linux/Unix guru!

Happy compiling!