[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1. Building a cross-compiler

This section shows how to setup a cross compiler to compile on one machine that runs on another machine. While the examples use a host of i686-pc-linux-gnu, these instructions are generic and should work on any platform, subject to the limits of the compiler and assembler.

PrerequisitesWhat you will need to begin.
Building the Cross CompilerStep by step instructions.
Additional LibrariesHow to deal with non-system libraries.




[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 Prerequisites

You should be familiar with compiling GCC and glibc before continuing. Building a cross compiler is not difficult, but you should make sure that you have enough experience before attempting this.

You will need GCC and GNU Make to begin. You cannot build a cross-compiler from the compiler that comes with most systems, and several components use GNU Make extensions. You will also need any other the programs to support these builds, like gawk, sed, bison, and friends. If you have don't know what you need, consider reviewing building gcc and glibc awhile before going on.

These instructions assume that you have write access to `/usr/local'. If you do not, you should change the `prefix'. `prefix'/bin should be in your path.

The build requires about 750 MB to complete, and the resulting binaries will consume around 300 MB.

If you are unsure of any of these steps, DO NOT CONTINUE. If a bad option is passed to `configure' or `make', you may OVERWRITE your local C library, or C compiler, leaving your system in an UNUSABLE state. You have been warned.

The following web sites can help you get started:

Make sure you have the following programs(1) are unpacked on your harddrive. Version numbers have been suggested here because they are known to work(2). If you try a more recent version and it works, please report that to bug-hurd@gnu.org. Where `CVS' is noted as the version number, it is because the product changes frequently and there are very few releases. CVS builds, however, may be broken and aren't tested as well as released versions. If you experience difficulty with a package checked out from CVS, wait a few days and get an update - most problems are fixed fairly quickly.

H.J. Lu takes periodic snapshots of the binutils, and makes some linux-specific changes to them. While these are not official releases of binutils, they are more stable than simply pulling down CVS versions. You can find these at ftp://ftp.valinux.com/pub/support/hjl/binutils/.




[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 Building the Cross Compiler

To begin, unpack or checkout all of your packages in a directory. Then, create a series of build directories. Your directory should look like this:

$ ls -al
total 21
drwxrwxr-x  14 jbailey  jbailey      1024 Dec 19 11:30 .
drwx------  77 jbailey  jbailey      8192 Dec 19 11:29 ..
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:29 binutils
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:30 build.binutils
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:30 build.egcs
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:30 build.gcc
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:30 build.glibc
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:30 build.gnumach
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:30 build.mig
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:29 egcs-1.1.2
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:29 gcc-2.95.2
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:30 glibc-2.1.2
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:29 gnumach
drwxrwxr-x   2 jbailey  jbailey      1024 Dec 19 11:29 mig
$
It used to be customary to build with the object directory inside the source directory, but that is no longer supported.

  1. binutils:
    cd build.binutils
    ../binutils/configure --prefix=/usr/local --target=i586-pc-gnu
    make
    make check
    make install
    cd ..

  2. egcs: If you ignored the earlier warning not to continue without 750 MB of drive space free and are thinking about deleting the build dirs when you are done, do not delete this one. You will need it again.

    This step depends on some later steps to complete, so will fail with an error. Don't panic.


    cd build.egcs
    ../egcs-1.1.2/configure --prefix=/usr/local --target=i586-pc-gnu --with-gnu-as --with-gnu-ld
    make -k
    make -k install
    cd ..

  3. gnumach:
    cd build.gnumach
    ../gnumach/configure --build=i686-pc-linux-gnu --host=i586-pc-gnu
    make -k install-headers prefix=/usr/local/i586-pc-gnu
    cd ..

  4. mig:
    cd build.mig
    ../mig/configure --target=i586-pc-gnu --host=i686-pc-linux-gnu --prefix=/usr/local
    make
    make install
    cd ..

  5. Rename gcc to egcs: This allows the 2 compilers to co-exist on the same system. If you ever want to use egcs instead of gcc for compiling something, set CC=i586-pc-gnu-egcs.


    mv /usr/local/bin/i586-pc-gnu-gcc /usr/local/bin/i586-pc-gnu-egcs

  6. gcc: If you ignored the earlier warning not to continue without 750 MB of drive space free and are thinking about deleting the build dirs when you are done, do not delete this one. You will need it again.

    This step depends on some later steps to complete, so will fail with an error. Don't panic.


    cd build.gcc
    ../gcc-2.95.2/configure --prefix=/usr/local --target=i586-pc-gnu --with-gnu-as --with-gnu-ld
    make -k
    make -k install
    cd ..
    ln -s /usr/local/i586-pc-gnu/ /usr/local/lib/gcc-lib/i586-pc-gnu/2.95.2/i586-pc-gnu

  7. hurd:
    ../hurd/configure --build=i686-pc-linux-gnu --host=i586-pc-gnu --prefix=/usr/local/i586-pc-gnu --disable-profile
    make install-headers no_deps=t
    cd ..

  8. glibc: The `configure' script in glibc allows you to select all of the add-ons. You should specify them explicitely for the hurd, because linking linuxthreads in by accident will cause problems.

    This is also a bad directory to delete.


    cd build.glibc
    ../glibc-2.1.2/configure --without-cvs --enable-add-ons=crypt --build=i686-pc-linux-gnu --host=i586-pc-gnu --prefix= --disable-profile
    make -k install-headers install_root=/usr/local/i586-pc-gnu
    cp ../glibc-2.1.2/include/features.h /usr/local/i586-pc-gnu/include/features.h
    mkdir /usr/local/i586-pc-gnu/include/gnu
    touch /usr/local/i586-pc-gnu/include/gnu/stubs.h
    cd ..

    The stubs file will be correctly overwritten later on when we do the full glibc install. However, the file isn't generated until the last possible moment, so make install-headers doesn't pick it up.

  9. egcs: If you deleted egcs before (despite warnings indicating that you shouldn't) you will have to go back and redo the earlier step. However, the install should complete succesfully this time, and this step won't be needed.


    cd build.egcs
    make
    make install
    cd ..

  10. gcc: If you deleted egcs before (despite warnings indicating that you shouldn't) you will have to go back and redo the earlier step. However, the install should complete succesfully this time, and this step won't be needed.


    cd build.gcc
    make
    make install
    cd ..

  11. glibc: The compiler is now fully functional and should cheerfully complete the compile.


    cd build.glibc
    make
    make install install_root=/usr/local/i586-pc-gnu
    cd ..

  12. Fixing libc.so: There is a default instruction for the hurd to tell it where to find some of it's libraries. This will confuse the linker into thinking that the libc is really in `/lib' on your system. Symlinking this file to the real libc.so will solve the problem.


    ln -s -f /usr/local/i586-pc-gnu/lib/libc.so.0.2 /usr/local/i586-pc-gnu/lib/libc.so




[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 Additional Libraries

It should be safe to simply copy any built libraries and headers into appropraite directories under /usr/local/i586-pc-gnu/




[Top] [Contents] [Index] [ ? ]

Footnotes

(1)

These instructions have not been tested using anything other than the C compiler. It is possible that you could build a cross-C++ (and friends) compiler using these instructions.

(2)

Both egcs-1.1.2 and gcc-2.95.2 are included here because the latest gcc will not compile gnumach or the hurd. This is due to some invalid code in those programs that used to be permissable.



[Top] [Contents] [Index] [ ? ]

Table of Contents



[Top] [Contents] [Index] [ ? ]

Overview (Short Table of Contents)

1. Building a cross-compiler


[Top] [Contents] [Index] [ ? ]

About this document

This document was generated with texi2html 1.60Beta on December, 27 1999 by Jeff Bailey.

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ < ] Back previous section in reading order 1.2.2
[ > ] Forward next section in reading order 1.2.4
[ << ] FastBack previous or up-and-previous section 1.1
[ Up ] Up up section 1.2
[ >> ] FastForward next or up-and-next section 1.3
[Top] Top cover (top) of document  
[Contents] Contents table of contents  
[Index] Index concept index  
[ ? ] About this page  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:

This document was generated using texi2html by Jeff Bailey   on December, 27 1999