Skip to content

Instantly share code, notes, and snippets.

@firejdl
Forked from steakunderscore/arm-elf-gcc_on_osx.sh
Last active December 29, 2015 20:29
Show Gist options
  • Save firejdl/7724496 to your computer and use it in GitHub Desktop.
Save firejdl/7724496 to your computer and use it in GitHub Desktop.
Build newlib, gdb, binutils, and gcc for targetting arm-elf. Changes from @steakunderscore's version: I updated all software to the latest version (e.g. the latest version of the 4.6 branch of gcc is 4.6.4). I made it possible to run this script in parts, commenting out all but the part that I was currently compiling, to ensure each part compile…
#!/bin/bash
# number of threads to use for compilation
export THREADS=4
mkdir toolchain
cd toolchain
# grab sources
wget ftp://sources.redhat.com/pub/newlib/newlib-1.20.0.tar.gz
wget http://ftp.gnu.org/gnu/gdb/gdb-7.6.1.tar.bz2
wget http://ftp.gnu.org/gnu/binutils/binutils-2.23.2.tar.bz2
wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.4/gcc-core-4.6.4.tar.bz2
wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.4/gcc-g++-4.6.4.tar.bz2
# extra libs needed to compile gcc
wget http://ftp.gmplib.org/gmp/gmp-5.1.3.tar.bz2
wget http://www.mpfr.org/mpfr-current/mpfr-3.1.2.tar.bz2
wget http://www.multiprecision.org/mpc/download/mpc-1.0.1.tar.gz
# extract sources
tar xvf newlib-1.20.0.tar.gz
tar xvf gdb-7.6.1.tar.bz2
tar xvf binutils-2.23.2.tar.bz2
tar xvf gcc-core-4.6.4.tar.bz2
tar xvf gcc-g++-4.6.4.tar.bz2
# extra libs needed to compile gcc
tar xvf gmp-5.1.3.tar.bz2
tar xvf mpfr-3.1.2.tar.bz2
tar xvf mpc-1.0.1.tar.gz
export target=arm-elf
export prefix=/usr/local/$target
export PATH=$prefix/bin:$PATH
# install extra libs needed to compile gcc first
cd gmp-5.1.3
mkdir build
cd build
../configure --enable-cxx
make -j$THREADS
make check
sudo make install
cd ../..
cd mpfr-3.1.2
mkdir build
cd build
../configure --with-gmp=/usr/local
make -j$THREADS
make check
sudo make install
cd ../..
cd mpc-1.0.1
mkdir build
cd build
../configure --with-gmp=/usr/local --with-mpfr=/usr/local
make -j$THREADS
make check
sudo make install
cd ../..
mkdir -p $prefix/bin
cd binutils-2.23.2
mkdir build-$target
cd build-$target
../configure --target=$target --prefix=$prefix --enable-interwork --enable-multilib --disable-nls --disable-shared --disable-threads --with-gcc --with-gnu-as --with-gnu-ld --enable-werror=no
make -j$THREADS
sudo make install
cd ../..
cd gcc-4.6.4
sed -i '.bak' 's~# MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork~MULTILIB_OPTIONS += mno-thumb-interwork/mthumb-interwork~' gcc/config/arm/t-arm-elf
sed -i '.bak' 's~# MULTILIB_DIRNAMES += normal interwork~MULTILIB_DIRNAMES += normal interwork~' gcc/config/arm/t-arm-elf
mkdir build-$target
cd build-$target
../configure --target=$target --prefix=$prefix --disable-nls --disable-shared --disable-threads --with-gcc --with-gnu-ld --with-gnu-as --with-dwarf2 --enable-languages=c,c++ --enable-interwork --enable-multilib --with-newlib --with-headers=../../newlib-1.19.0/newlib/libc/include --disable-libssp --disable-libstdcxx-pch --disable-libmudflap --disable-libgomp -v --enable-werror=no --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local
mkdir -p libiberty libcpp fixincludes
make all-gcc -j$THREADS
sudo make install-gcc
cd ../..
cd newlib-1.20.0
mkdir build-$target
cd build-$target
../configure --target=$target --prefix=$prefix --enable-interwork --enable-multilib
make -j$THREADS
sudo make install
cd ../..
cd gcc-4.6.4/build-$target
make -j$THREADS
sudo make install
cd ../..
cd gdb-7.6.1
mkdir build-$target
cd build-$target
../configure --target=$target --prefix=$prefix --disable-nls
make -j$THREADS
sudo make install
cd ../..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment