tisdag 15 juni 2010

Building a gcc cross compiler

This was based on an example from http://www.arklyffe.com/main/content/arm-gcc-toolchain-build, but I had to use --disable-multilib to get gcc to compile. Or else, it would fail some of its ./configuration steps (I think for instance libz failed).

Note that gcc is built twice, once to get a boot strap compiler that can compile newlib for the target platform, and then again to compile gcc to use newlib as its C library.

# build tool chain
TARGET=arm-none-eabi
TARGET=i486-none-elf
INSTALL=$HOME/test/$TARGET
GCC_VER=4.5.0
###

export PATH=$INSTALL/bin:$PATH

mkdir $INSTALL
cd $INSTALL
mkdir build
cd build

(
wget http://ftp.sunet.se/pub/gnu/gmp/gmp-5.0.1.tar.bz2 &
wget http://ftp.sunet.se/pub/gnu/mpfr/mpfr-2.4.2.tar.bz2 &
wget http://ftp.sunet.se/pub/gnu/gcc/infrastructure/mpc-0.8.1.tar.gz &
wait
)

tar -xjf gmp-5.0.1.tar.bz2
tar -xjf mpfr-2.4.2.tar.bz2
tar -xzf mpc-0.8.1.tar.gz

(
wget http://ftp.sunet.se/pub/gnu/binutils/binutils-2.20.tar.bz2 & 
wget http://ftp.sunet.se/pub/gnu/gcc/releases/gcc-$GCC_VER/gcc-core-$GCC_VER.tar.bz2 &
wget http://ftp.sunet.se/pub/gnu/gcc/releases/gcc-$GCC_VER/gcc-g++-$GCC_VER.tar.bz2 &
wget http://ftp.sunet.se/pub/gnu/gdb/gdb-7.1.tar.bz2 &
wait
)
tar -xjf binutils-2.20.tar.bz2
tar -xjf gcc-core-$GCC_VER.tar.bz2
tar -xjf gcc-g++-$GCC_VER.tar.bz2
tar -xjf gdb-7.1.tar.bz2

wget ftp://sources.redhat.com/pub/newlib/newlib-1.18.0.tar.gz
tar -xzf newlib-1.18.0.tar.gz

mkdir gmp-5.0.1/build; cd gmp-5.0.1/build
../configure --prefix=$INSTALL/build/gmp --disable-shared --enable-static
make -j8 && make install
cd ../../
mkdir mpfr-2.4.2/build; cd mpfr-2.4.2/build
../configure --prefix=$INSTALL/build/mpfr --with-gmp=$INSTALL/build/gmp \
   --disable-shared --enable-static
make -j8 && make install
cd ../../
mkdir mpc-0.8.1/build; cd mpc-0.8.1/build
../configure --prefix=$INSTALL/build/mpc --with-gmp=$INSTALL/build/gmp \
   --with-mpfr=$INSTALL/build/mpfr --disable-shared --enable-static
make -j8 && make install
cd ../../

patch -l -p0 <<EOF
--- binutils-2.20/gas/as.h      2010-06-15 18:49:19.771279712 +0000
+++ binutils-2.20/gas/as.h      2010-06-15 18:50:10.400278790 +0000
@@ -238,7 +238,7 @@
 #define know(p) gas_assert(p)  /* Verify our assumptions!  */
 #endif /* not yet defined */
 #else
-#define know(p)                        /* know() checks are no-op.ed  */
+#define know(p)        do {} while(0)  /* know() checks are no-op.ed  */
 #endif
 
 /* input_scrub.c */
EOF

mkdir binutils-2.20/build; cd binutils-2.20/build
../configure --prefix=$INSTALL --target=$TARGET --enable-interwork \
   --enable-multilib --disable-nls --disable-shared --disable-threads \
   --with-gcc --with-gnu-as --with-gnu-ld
make -j8 && make install
cd ../../

mkdir gcc-$GCC_VER/build; cd gcc-$GCC_VER/build
../configure --prefix=$INSTALL --target=$TARGET --enable-interwork \
   --disable-multilib --enable-languages=c --with-newlib --disable-nls \
   --disable-shared --disable-threads --with-gnu-as --with-gnu-ld \
   --with-gmp=$INSTALL/build/gmp --with-mpfr=$INSTALL/build/mpfr \
   --with-mpc=$INSTALL/build/mpc --without-headers
make -j8 all-gcc && make install-gcc
cd ../../

mkdir newlib-1.18.0/build; cd newlib-1.18.0/build
../configure --prefix=$INSTALL --target=$TARGET --enable-interwork \
   --enable-multilib --with-gnu-as --with-gnu-ld --disable-nls 
make -j8 && make install
cd ../../

rm -rf gcc-$GCC_VER/build
mkdir gcc-$GCC_VER/build; cd gcc-$GCC_VER/build
../configure --prefix=$INSTALL --target=$TARGET --enable-interwork \
   --disable-multilib --enable-languages=c,c++ --with-newlib --disable-nls \
   --disable-shared --disable-threads --with-gnu-as --with-gnu-ld \
   --with-gmp=$INSTALL/build/gmp --with-mpfr=$INSTALL/build/mpfr \
   --with-mpc=$INSTALL/build/mpc
make -j8 && make install
cd ../../

Inga kommentarer:

Skicka en kommentar