Compiling and Installing the GNU Tools under Linux or Unix

Method 1: Combined 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 two to 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 (as described in this document), by compiling the individual source directories, or by recreating the binary package. In general, the simplest of these three methods is the one described here: it tends to be less problematic, slightly faster and somewhat more convenient, as it involves less steps. The individual sources method should only be used when this one 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 two to 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 directory that will contain the combined sources and change to it:
mkdir combined
cd combined
7. Create symbolic links to the real source code files for the binutils, gcc and newlib packages, using the symlink-tree script that is supplied on the CD-ROM:
/mnt/cdrom/utils/unsw/src/symlink-tree ../binutils-2.14 ../gcc-3.3 ../newlib-1.11.0
Please note that you may need to insert a corrective step (essentially, step 7a) at this point to fix up certain symbolic links, depending on the version numbers of the archive files. See the section on common problems for more details. This corrective step is not necessary with gcc 3.3 and binutils 2.14.
8. Create a separate directory in which to build the sources. In this document, /var/tmp/build will be used:
mkdir /var/tmp/build
cd /var/tmp/build
mkdir combined insight-5.3
9. Configure the combined sources:
cd /var/tmp/build/combined
/var/tmp/src/combined/configure --target=arm-elf --with-newlib
10. Configure insight. This package requires the X11 Window System header files and libraries:
cd ../insight-5.3
/var/tmp/src/insight-5.3/configure --target=arm-elf
11. Compile the combined sources. Once you have issued this command, you can go for an extended coffee break…
cd ../combined && make all && cd ../insight-5.3 && make all
(If the compilation terminates with an error, read the section on common problems for some suggestions of what you should check.)
12. As the root superuser, install the compiled combined sources. You will need the root superuser’s password:
/bin/su
cd ../combined && make install && cd ../insight-5.3 && make install
13. 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.2.1
strip cc1 cc1plus collect2 cpp0 tradcpp0
exit
14. (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
15. 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. The following is a list of things you should check if the compilation (the “make all” step) terminates with an error:

1. 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.
2. One of the non-obvious things to check is that the /usr/local/arm-elf/sys-include directory does not exist on your system. If it does exist, remove it and reissue make all. If that still fails, type rm -fr /var/tmp/build/combined/*, then jump back to step 9.
3. The method of compilation described in this document sometimes fails due to version mismatches of files in shared directories. The usual symptom is an error message that a particular function or include file could not be found (an “undefined reference”). Fixing this requires you to experiment a little with the symlink-tree program (used in step 7). It helps to understand just what is going on.
All of the individual components (source code archives) that form part of the GNU Tools are generated from a single CVS repository. Parts of these archives are directories that are shared between various components. Sometimes these shared directories can become “out of sync” with each other: this happens if the individual components are released at different times, and development continues on files in those shared directories in the meantime.
This problem is a real one for some versions of binutils and gcc! You may need to rearrange the order of directories listed in the symlink-tree command line (step 7) before you proceed to step 9: in general, the package that was released later (by date) is listed before an older package. Alternatively, you can experiment with the following command lines to fix the problem:
cd /var/tmp/src/combined
for d in include libiberty; do (cd $d; for q in `ls -lA | grep gcc | awk '{print $9}'`; do if [ -e ../../binutils-version/$d/$q ]; then echo $d/$q; rm $q; ln -s ../../binutils-version/$d/$q; fi; done); done
(Remember that the line beginning with “for d in” above is a single line! Note the use of the back-tick character “`” in this line. You also need to replace version with the version number of the binutils package, such as 2.13.2.1)
If you get as far as step 10 before you realise that you need to perform these acrobatics, you will need to delete everything in /var/tmp/build/combined (try rm -fr /var/tmp/build/combined/*), fix what is needed, then jump to step 9.

If none of these suggestions help you, try compiling the GNU Tools using the individual sources method instead of this one. You will need to start from scratch, so issue the following commands to delete everything in /var/tmp/src and /var/tmp/build:

cd /var/tmp
rm -fr src build

Happy compiling!