Skip to content

Instantly share code, notes, and snippets.

@ckirsch
Created August 19, 2013 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckirsch/6265486 to your computer and use it in GitHub Desktop.
Save ckirsch/6265486 to your computer and use it in GitHub Desktop.
This is a script for building gcc cross compilers.
# Building xgcc for C:
# On a mac install the latest gcc binaries via macports.org:
sudo port install gcc48
port select --list gcc
sudo port select --set gcc mp-gcc48
hash -r
# Building xgcc:
# Download and extract binutils, gcc, newlib, and gdb sources:
cd $HOME/Downloads
wget ftp://ftp.gnu.org/pub/gnu/binutils/binutils-2.23.2.tar.bz2
wget ftp://ftp.gnu.org/pub/gnu/gcc/gcc-4.8.1/gcc-4.8.1.tar.bz2
wget ftp://sources.redhat.com/pub/newlib/newlib-1.20.0.tar.gz
wget ftp://ftp.gnu.org/pub/gnu/gdb/gdb-7.6.tar.bz2
tar zxvf binutils-2.23.2.tar.bz2
tar zxvf gcc-4.8.1.tar.bz2
tar zxvf newlib-1.20.0.tar.gz
tar zxvf gdb-7.6.tar.bz2
# Download gcc dependencies:
cd gcc-4.8.1
./contrib/download_prerequisites
cd ..
# Select target
export TARGET=mips-elf
# For i386-elf:
# export TARGET=i386-elf
export PREFIX=$HOME/Dropbox/Tools/$TARGET
export PATH=$PATH:$PREFIX/bin
# Configure and build binutils:
mkdir binutils-build
cd binutils-build
../binutils-2.23.2/configure --target=$TARGET --prefix=$PREFIX
make
make install
cd ..
# Configure and build bootstrap xgcc:
mkdir gcc-build
cd gcc-build
../gcc-4.8.1/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c --without-headers --with-newlib --with-gnu-as --with-gnu-ld
make all-gcc
make install-gcc
cd ..
# Configure and build newlib:
mkdir newlib-build
cd newlib-build
../newlib-1.20.0/configure --target=$TARGET --prefix=$PREFIX
make
make install
# Configure and build xgcc:
cd gcc-build
../gcc-4.8.1/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c --with-newlib --with-gnu-as --with-gnu-ld --disable-shared --disable-libssp
make
make install
cd ..
# Configure and build gdb:
mkdir gdb-build
cd gdb-build
../gdb-7.6/configure --target=$TARGET --prefix=$PREFIX --disable-tui
make
make install
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment