Created
October 20, 2014 05:18
-
-
Save madmo/ff33d7e2d85d96430f73 to your computer and use it in GitHub Desktop.
gcc toolchain cretion script for pic32
This file contains 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
#!/bin/bash | |
set -e | |
# | |
# Path definitions | |
# | |
TOOLCHAIN_ROOT_DIR="${PWD}/$(dirname $0)" | |
TOOLCHAIN_DL_DIR="${TOOLCHAIN_ROOT_DIR}/dl" | |
TOOLCHAIN_OUT_DIR="${TOOLCHAIN_ROOT_DIR}/output" | |
TOOLCHAIN_BUILD_DIR="${TOOLCHAIN_OUT_DIR}/build" | |
TOOLCHAIN_INSTALL_DIR="${TOOLCHAIN_OUT_DIR}/install" | |
function die() | |
{ | |
echo "$@" | |
exit 1 | |
} | |
function download() | |
{ | |
mkdir -p "${TOOLCHAIN_DL_DIR}" || die "mkdir failed" | |
( cd "${TOOLCHAIN_DL_DIR}" && wget -c "$1" ) || die "download failed" | |
} | |
function downloadGit() | |
{ | |
URL=$1 | |
REV=$2 | |
PKG=$3 | |
mkdir -p "${TOOLCHAIN_DL_DIR}/${PKG}-${REV}" || die "mkdir failed" | |
git init "${TOOLCHAIN_DL_DIR}/${PKG}-${REV}" || die "git init failed" | |
( | |
set -e | |
cd "${TOOLCHAIN_DL_DIR}/${PKG}-${REV}" | |
git remote add origin "$URL" | |
git fetch origin "$REV" | |
git reset --hard FETCH_HEAD | |
) || die "download failed" | |
tar -C "${TOOLCHAIN_DL_DIR}" -czf "${TOOLCHAIN_DL_DIR}/${PKG}-${REV}.tar.gz" "${PKG}-${REV}" | |
} | |
function extract() | |
{ | |
mkdir -p "${TOOLCHAIN_BUILD_DIR}" || die "mkdir failed" | |
tar -C "${TOOLCHAIN_BUILD_DIR}" -xf "${TOOLCHAIN_DL_DIR}/$1" || die "extract failed" | |
} | |
# | |
# package versions | |
# | |
BINUTILS_VERSION=2.24 | |
MPFR_VERSION=3.1.2 | |
GMP_VERSION=5.1.3 | |
MPC_VERSION=1.0.1 | |
GCC_VERSION=4.8.1 | |
NEWLIB_VERSION=2.1.0 | |
PIC32_PART_VERSION=master | |
# | |
# build variables | |
# | |
TARGET=mips-elf | |
PREFIX=/usr/local | |
MAKEFLAGS="-j 6" | |
export PATH="${TOOLCHAIN_INSTALL_DIR}/${PREFIX}/bin:$PATH" | |
# | |
# download stuff | |
# | |
download "http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz" | |
download "http://ftp.gnu.org/gnu/mpfr/mpfr-${MPFR_VERSION}.tar.gz" | |
download "http://ftp.gnu.org/gnu/gmp/gmp-${GMP_VERSION}.tar.gz" | |
download "http://ftp.gnu.org/gnu/mpc/mpc-${MPC_VERSION}.tar.gz" | |
download "http://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz" | |
download "ftp://sourceware.org/pub/newlib/newlib-${NEWLIB_VERSION}.tar.gz" | |
downloadGit "https://github.com/jasonkajita/pic32-part-support.git" "${PIC32_PART_VERSION}" "pic32_part_support" | |
# | |
# extract stuff | |
# | |
extract "binutils-${BINUTILS_VERSION}.tar.gz" | |
extract "gcc-${GCC_VERSION}.tar.gz" | |
extract "mpfr-${MPFR_VERSION}.tar.gz" | |
extract "gmp-${GMP_VERSION}.tar.gz" | |
extract "mpc-${MPC_VERSION}.tar.gz" | |
extract "newlib-${NEWLIB_VERSION}.tar.gz" | |
extract "pic32_part_support-${PIC32_PART_VERSION}.tar.gz" | |
# | |
# build binutils | |
# | |
( | |
set -e | |
cd "${TOOLCHAIN_BUILD_DIR}/binutils-${BINUTILS_VERSION}" | |
mkdir build | |
cd build | |
../configure --disable-werror --target=$TARGET --prefix=$PREFIX | |
make all $MAKEFLAGS | |
make install DESTDIR="${TOOLCHAIN_INSTALL_DIR}" | |
) || die "binutils build failed" | |
# | |
# build gcc and newlib | |
# | |
( | |
set -e | |
cd "${TOOLCHAIN_BUILD_DIR}/gcc-${GCC_VERSION}" | |
# | |
# symlink dependent libs | |
# | |
ln -sf "${TOOLCHAIN_BUILD_DIR}/mpfr-${MPFR_VERSION}" mpfr | |
ln -sf "${TOOLCHAIN_BUILD_DIR}/mpfr-${GMP_VERSION}" gmp | |
ln -sf "${TOOLCHAIN_BUILD_DIR}/mpc-${MPC_VERSION}" mpc | |
ln -sf "${TOOLCHAIN_BUILD_DIR}/newlib-${NEWLIB_VERSION}/newlib" newlib | |
mkdir build | |
cd build | |
../configure --target=$TARGET --prefix=$PREFIX \ | |
--enable-languages=c,c++ \ | |
--with-arch-32=mips32r2 \ | |
--enable-lto \ | |
--disable-nls \ | |
--disable-shared \ | |
--disable-libstdc___v3 \ | |
--disable-decimal-float \ | |
--disable-threads \ | |
--disable-libmudflap \ | |
--disable-libssp \ | |
--disable-libgomp \ | |
--disable-libquadmath \ | |
--with-newlib --with-headers=newlib/libc/include \ | |
--disable-newlib-supplied-syscalls \ | |
--disable-libgloss | |
make all $MAKEFLAGS | |
make install DESTDIR="${TOOLCHAIN_INSTALL_DIR}" | |
) || die "gcc and newlib build failed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment