Last active
May 27, 2023 07:47
-
-
Save cjmeyer/4251208 to your computer and use it in GitHub Desktop.
Bash: Build Binutils, GCC, Newlib, and GDB for ARM EABI (Cross-compiler).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# Target and build configuration. | |
TARGET=arm-none-eabi | |
PREFIX=/opt/arm-none-eabi-4.7.1 | |
# Sources to build from. | |
BINUTILS=binutils-2.23.1 | |
GCC=gcc-4.7.1 | |
NEWLIB=newlib-1.20.0 | |
GDB=gdb-7.5 | |
# Grab the souce files...but only if they don't already exist. | |
if [ ! -e ${BINUTILS}.tar.bz2 ]; then | |
echo "Grabbing ${BINUTILS}.tar.bz2" | |
curl ftp://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2 -o ${BINUTILS}.tar.bz2 | |
fi | |
if [ ! -e ${GCC}.tar.bz2 ]; then | |
echo "Grabbing ${GCC}.tar.bz2" | |
curl ftp://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.bz2 -o ${GCC}.tar.bz2 | |
fi | |
if [ ! -e ${NEWLIB}.tar.gz ]; then | |
echo "Grabbing ${NEWLIB}.tar.gz" | |
curl ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz -o ${NEWLIB}.tar.gz | |
fi | |
if [ ! -e ${GDB}.tar.bz2 ]; then | |
echo "Grabbing ${GDB}.tar.bz2" | |
curl ftp://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2 -o ${GDB}.tar.bz2 | |
fi | |
# Extract the sources. | |
echo -n "extracting binutils... " | |
tar -jxf ${BINUTILS}.tar.bz2 | |
echo "done" | |
echo -n "extracting gcc... " | |
tar -jxf ${GCC}.tar.bz2 | |
echo "done" | |
echo -n "extracting newlib... " | |
tar -zxf ${NEWLIB}.tar.gz | |
echo "done" | |
echo -n "extracting gdb... " | |
tar -jxf ${GDB}.tar.bz2 | |
echo "done" | |
# Build a set of compatible Binutils for this architecture. Need this before | |
# we can build GCC. | |
mkdir binutils-build | |
cd binutils-build | |
../${BINUTILS}/configure --target=${TARGET} --prefix=${PREFIX} --disable-nls \ | |
--enable-interwork --enable-multilib --disable-werror | |
make all install 2>&1 | tee ../make.log | |
cd .. | |
# Add the new Binutils to the path for use in building GCC and Newlib. | |
export PATH=$PATH:${PREFIX}:${PREFIX}/bin | |
# Build and configure GCC with the Newlib C runtime. Note that the 'with-gmp', | |
# 'with-mpfr' and 'with-libconv-prefix' are needed only for Mac OS X using the | |
# MacPorts system. | |
cd ${GCC} | |
# The following symbolic links are only needed if building Newlib as well. | |
ln -s ../${NEWLIB}/newlib . | |
ln -s ../${NEWLIB}/libgloss . | |
mkdir ../gcc-build | |
cd ../gcc-build | |
../${GCC}/configure --target=${TARGET} --prefix=${PREFIX} \ | |
--with-newlib --with-gnu-as --with-gnu-ld --disable-nls --disable-libssp \ | |
--disable-gomp --disable-libstcxx-pch --enable-threads --disable-shared \ | |
--disable-libmudflap --enable-interwork --enable-languages=c,c++ \ | |
--with-gmp=/opt/local --with-mpfr=/opt/local --with-libiconv-prefix=/opt/local | |
make all install 2>&1 | tee -a ../make.log | |
# Use the following instead if only building and installing GCC (i.e. without Newlib). | |
#make all-gcc install-gcc 2>&1 | tee -a ../make.log | |
cd .. | |
# Build GDB. | |
mkdir gdb-build | |
cd gdb-build | |
../${GDB}/configure --target=${TARGET} --prefix=${PREFIX} \ | |
--disable-interwork --enable-multilib --disable-werror | |
make all install 2>&1 | tee -a ../make.log | |
cd .. | |
# We are done, let the user know were the new compiler and tools are. | |
echo "" | |
echo "Cross GCC for ${TARGET} installed to ${PREFIX}" | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment