Hack your own cross compiler

2009-03-06

I’ve made a custom cross-compilation toolchain for ARM processors. It works either
as a standalone toolchain or within Scratchbox2.

http://zenvoid.org/software/cross-compiler/

Most precompiled toolchains were not suitable for my own purposes since I needed a very specific version of binutils and glibc, and trying to build CodeSourcery’s toolchains with their included script was too much masochistic.

The source code and build script is included, and unlike the build script
in CodeSourcery toolchains, this one actually works. It is meant to be
hacked, built from source code to create toolchains with custom patches
or with different tool and library versions.

Building from source

GCC 4.2 is the default compiler used for building and it is required to
compile the toolchain from source code.

The shell script build_toolchain performs the compilation and
installation of all components in the right order. It is tested under
Ubuntu (intrepid) 32bit, but it should also work in Debian and most other
GNU/Linux distributions. It must be run inside the source directory.

./build_toolchain

The default location is /usr/local/toolchain-TARGET-VERSION. To install
the toolchain in your home directory or any other location, set the
INSTALLDIR variable.

INSTALLDIR=/opt/toolchain-arm-2008.12.rgs2 ./build_toolchain

The -c parameter selects another compiler for building (though not all
compilers will work).

./build_toolchain -c gcc

It is possible to manually override the target and build architectures.
The target can be set to x86 to get a native toolchain (which is useful
under Scratchbox2); the default is an ARM cross compiler target. The ia64
architecture is untested and other targets are not supported.

./build_toolchain -t arm-none-linux-gnueabi -b i686-pc-linux-gnu
./build_toolchain -t i486-pc-linux-gnu -b i486-pc-linux-gnu

Modifications and custom toolchains

To use different components, edit the build script and change the
variables refering to source packages:

binutils_src_pkg='binutils-2.18.tar.bz2'
binutils_src_dir='binutils-2.18'
gcc_src_pkg='gcc-2008q1-126.tar.bz2'
gcc_src_dir='gcc-4.2'
[...]

You’ll probably need to also change build options, source patches and
other things, use your imagination ;-)

Please share your improvements and custom build scripts, modifications
for other architectures, different compilers or libraries, bug fixes…
they could be useful to other people and will be included in future
releases.

Filed under: Embedded, Software — Tags: , ,

Comments

  1. Comment by Volodymyr Shcherbyna

    2010-01-26 @ 23:28

    Hello. Thanks for a userful article!

    I am building the toolchain-src-karmic.rgs0 and I got the following errors after I execute
    $sudo ./build_toolchain

    Depend stdlib/Depend stdio-common/Depend libio/Depend malloc/Depend string/Depend wcsmbs/Depend time/Depend posix/Depend iconvdata/Depend nss/Depend localedata/Depend rt/Depend debug/Depend > /home/volodymyr/development/toolchain-src-karmic.rgs0/build/sysd-sorted-tmp
    mawk: scripts/gen-sorted.awk: line 19: regular expression compile failed (bad class — [], [^] or [)
    /[^
    mawk: scripts/gen-sorted.awk: line 19: syntax error at or near ]
    mawk: scripts/gen-sorted.awk: line 19: runaway regular expression /, "", subd …
    make[1]: Leaving directory `/home/volodymyr/development/toolchain-src-karmic.rgs0/eglibc-2.10.1'
    make[1]: Entering directory `/home/volodymyr/development/toolchain-src-karmic.rgs0/eglibc-2.10.1'
    mawk -f scripts/gen-sorted.awk \
    -v subdirs='csu assert ctype locale intl catgets math setjmp signal stdlib stdio-common libio malloc string wcsmbs time dirent grp pwd posix io termios resource misc socket sysvipc gmon gnulib iconv iconvdata wctype manual shadow gshadow po argp crypt nss localedata timezone rt conform debug libidn dlfcn elf' \
    -v srcpfx='' \
    nptl/sysdeps/pthread/Subdirs sysdeps/unix/inet/Subdirs sysdeps/unix/Subdirs assert/Depend intl/Depend catgets/Depend stdlib/Depend stdio-common/Depend libio/Depend malloc/Depend string/Depend wcsmbs/Depend time/Depend posix/Depend iconvdata/Depend nss/Depend localedata/Depend rt/Depend debug/Depend > /home/volodymyr/development/toolchain-src-karmic.rgs0/build/sysd-sorted-tmp
    mawk: scripts/gen-sorted.awk: line 19: regular expression compile failed (bad class — [], [^] or [)
    /[^
    mawk: scripts/gen-sorted.awk: line 19: syntax error at or near ]
    mawk: scripts/gen-sorted.awk: line 19: runaway regular expression /, "", subd …
    rm -f /home/volodymyr/development/toolchain-src-karmic.rgs0/build/stamp.o; > /home/volodymyr/development/toolchain-src-karmic.rgs0/build/stamp.o
    rm -f /home/volodymyr/development/toolchain-src-karmic.rgs0/build/stamp.os; > /home/volodymyr/development/toolchain-src-karmic.rgs0/build/stamp.os
    rm -f /home/volodymyr/development/toolchain-src-karmic.rgs0/build/stamp.oS; > /home/volodymyr/development/toolchain-src-karmic.rgs0/build/stamp.oS
    cd /home/volodymyr/development/toolchain-src-karmic.rgs0/build && /usr/local/toolchain-arm-karmic.rgs0/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ar cruv libc.a `cat stamp.o`
    : /home/volodymyr/development/toolchain-src-karmic.rgs0/build/libc.a
    cd /home/volodymyr/development/toolchain-src-karmic.rgs0/build && /usr/local/toolchain-arm-karmic.rgs0/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ar cruv libc_pic.a `cat stamp.os`
    : /home/volodymyr/development/toolchain-src-karmic.rgs0/build/libc_pic.a
    cd /home/volodymyr/development/toolchain-src-karmic.rgs0/build && /usr/local/toolchain-arm-karmic.rgs0/lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/bin/ar cruv libc_nonshared.a `cat stamp.oS`
    : /home/volodymyr/development/toolchain-src-karmic.rgs0/build/libc_nonshared.a
    make[1]: *** No rule to make target `/home/volodymyr/development/toolchain-src-karmic.rgs0/build/Versions.all', needed by `/home/volodymyr/development/toolchain-src-karmic.rgs0/build/abi-versions.h'. Stop.
    make[1]: Leaving directory `/home/volodymyr/development/toolchain-src-karmic.rgs0/eglibc-2.10.1'
    make: *** [all] Error 2

    I am in Ubuntu 9.10 x32 …

  2. Comment by Roberto

    2010-01-27 @ 10:45

    Most likely you don't have gawk installed, it seems that glibc fails to compile with mawk. Do "apt-get install gawk" and try again.

RSS feed for comments on this post.

Sorry, comments are closed at this time.

Alone in the Light


Copyright

Creative Commons License
Unless otherwise stated, articles and their accompanying pictures are licensed under a Creative Commons Attribution 3.0 Spain License.

Roberto Gordo Saez

roberto@zenvoid.org

Categories

Latest posts

Links