Skip to content

Instantly share code, notes, and snippets.

@RickKimball
Created December 28, 2011 20:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickKimball/1529568 to your computer and use it in GitHub Desktop.
Save RickKimball/1529568 to your computer and use it in GitHub Desktop.
msp430gcc toolchain fetcher/builder script
#!/usr/bin/env bash
# $Id: build-mspgcc 70 2011-11-05 19:40:36Z ice $
# 2012-02-04 kimballr - modified for latest FSF directory and
# sourceforge patch file name changes
# 2012-03-13 kimballr - added patches
#
# download, build and install GCC toolchain for MSP430
#
# prerequisites
# - bash
# - wget, GNU patch, GNU make
# - things needed to build binutils, GCC and GDB
#
# For Ubuntu/Debian that means:
# $ apt-get install build-essential; apt-get build-dep gcc
#
# environment
# - PREFIX - set to directory where toolchain is to be installed in
# (defaults to /opt/mspgcc, I like $HOME/opt/mspgcc)
#
# make a build directory $HOME/mspgcc
# cd $HOME/mspgcc;
# mv dowloaded/thissript.sh into $HOME/mspgcc
# chmod +x ./build-mspgcc.sh
# PREFIX=$HOME/opt/mspgcc ./build-mspgcc.sh
# export PATH=$HOME/opt/mspgcc/bin:$PATH
# mspgcc-430 -mmcu=msp430g2553 sample.c
set -e # bail out if anything fails
#set -x # uncomment to show line by line execution very verbose
mspgcc_ver="20110716"
binutils_lts_patches="sf3143071 sf3379341 sf3386145 sf3400711 sf3400750"
gcc_lts_patches="sf3370978 sf3390964 sf3394176 sf3396639 sf3409864 sf3417263 sf3431602 sf3433730 sf3420924 sf3500740"
gdb_lts_patches=""
libc_lts_patches="sf3387164 sf3402836"
mcu_lts_patches="sf3379189 sf3384550 sf3400714"
# ---
base_url="http://sourceforge.net/projects/mspgcc/files"
lts_patches_url="${base_url}/Patches/LTS/${mspgcc_ver}"
MSP430_ROOT="$( dirname -- $( readlink -f "${0}" ) )"
ncpus=1
uname_s="$( uname -s )"
case "${uname_s}" in
Linux|CYGWIN_NT)
G=""
ncpus="$( grep -c '^processor' /proc/cpuinfo )"
;;
*BSD)
localbase="/usr/local"
[ "${uname_s}" = "NetBSD" ] && localbase="/usr/pkg"
GCC_CONFG_ARGS="--with-gmp=${localbase} --with-mpfr=${localbase}"
G="g"
ncpus="$( sysctl -n hw.ncpu )"
;;
esac
dl()
{
local fn
# SF directlinks
fn="$( basename "${1%/download}" )"
[ -f "${fn}" ] && return
wget --content-disposition -qO "${fn}" "${1}"
}
if [ ! "${ncpus/[^0-9-]*/}" -o ${ncpus} -lt 1 ]
then
ncpus=1
fi
[ -d "${PREFIX}" ] && {
echo "${PREFIX} exists, remove manually"
exit 1
}
[ -d BUILD ] && rm -rf ./BUILD
exec > >( tee "${MSP430_ROOT}/build.log.$$" )
exec 2>&1
echo '!!! fetch+untar+patch mspgcc'
dl "${base_url}/mspgcc/mspgcc-${mspgcc_ver}.tar.bz2"
[ -d "mspgcc-${mspgcc_ver}" ] && rm -rf ./"mspgcc-${mspgcc_ver}"
tar xjf "mspgcc-${mspgcc_ver}.tar.bz2"
echo '!!! extract versions'
cd ./"mspgcc-${mspgcc_ver}"
if [ -f msp430-binutils-*.patch ]
then
set -- $( echo msp430-binutils-*.patch | sed -r 's!msp430-binutils-(.[^-]+)-(.[^.]+).patch!\1 \2!' )
binutils_upstream_ver="${1}"
binutils_patch_ver="${2}"
set --
else
echo "Can not extract binutils version information"
exit 1
fi
if [ -f msp430-gcc-*.patch ]
then
set -- $( echo msp430-gcc-*.patch | sed -r 's!msp430-gcc-(.[^-]+)-(.[^.]+).patch!\1 \2!' )
gcc_upstream_ver="${1}"
gcc_patch_ver="${2}"
set --
else
echo "Can not extract gcc version information"
exit 1
fi
if [ -f msp430-gdb-*.patch ]
then
set -- $( echo msp430-gdb-*.patch | sed -r 's!msp430-gdb-(.[^-]+)-(.[^.]+).patch!\1 \2!' )
gdb_upstream_ver="${1}a"
gdb_upstream_ver_orig="${1}"
gdb_patch_ver="${2}"
set --
else
echo "Can not extract gdb version information"
exit 1
fi
if [ -f msp430-libc.version ]
then
libc_ver="$(< msp430-libc.version )"
else
echo "Can not extract libc version information"
exit 1
fi
if [ -f msp430mcu.version ]
then
mcu_ver="$(< msp430mcu.version )"
else
echo "Can not extract mcu version information"
fi
cd ../
printf 'MSPGCC version: %s\n' "${mspgcc_ver}"
printf 'binutils version: %s\n' "${binutils_upstream_ver}"
printf 'binutils patch: %s\n' "${binutils_patch_ver}"
printf 'binutils LTS patches: %s\n' "${binutils_lts_patches}"
printf 'GCC version: %s\n' "${gcc_upstream_ver}"
printf 'GCC patch: %s\n' "${gcc_patch_ver}"
printf 'GCC LTS patches: %s\n' "${gcc_lts_patches}"
printf 'GDB version: %s\n' "${gdb_upstream_ver}"
printf 'GDB patch: %s\n' "${gdb_patch_ver}"
printf 'GDB LTS patches: %s\n' "${gdb_lts_patches}"
printf 'libc version: %s\n' "${libc_ver}"
printf 'libc LTS patches: %s\n' "${libc_lts_patches}"
printf 'MCU version: %s\n' "${mcu_ver}"
printf 'MCU LTS patches: %s\n' "${mcu_lts_patches}"
MSP430MCU_ROOT="${MSP430_ROOT}/msp430mcu-${mcu_ver}"
PREFIX="${PREFIX:-/opt/mspgcc}"
PATCH="${G}patch"
MAKE="${G}make -j ${ncpus}"
PATH=${PREFIX}/bin:${PATH}
export PREFIX MSP430_ROOT MSP430MCU_ROOT MAKE
echo '!!! fetch'
dl "http://ftp.gnu.org/pub/gnu/binutils/binutils-${binutils_upstream_ver}.tar.bz2"
dl "http://ftp.gnu.org/pub/gnu/gcc/gcc-${gcc_upstream_ver}/gcc-${gcc_upstream_ver}.tar.gz"
dl "http://ftp.gnu.org/pub/gnu/gdb/gdb-${gdb_upstream_ver}.tar.gz"
dl "${base_url}/msp430mcu/msp430mcu-${mcu_ver}.tar.bz2"
dl "${base_url}/msp430-libc/msp430-libc-${libc_ver}.tar.bz2"
echo '!!! untar+patch'
[ -d "binutils-${binutils_upstream_ver}" ] && rm -rf ./"binutils-${binutils_upstream_ver}"
tar jxf "binutils-${binutils_upstream_ver}.tar.bz2"
(
cd "binutils-${binutils_upstream_ver}"
${PATCH} -p1 < "../mspgcc-${mspgcc_ver}/msp430-binutils-${binutils_upstream_ver}-${binutils_patch_ver}.patch"
)
[ -d "gcc-${gcc_upstream_ver}" ] && rm -rf ./"gcc-${gcc_upstream_ver}"
tar xzf "gcc-${gcc_upstream_ver}.tar.gz"
(
cd "gcc-${gcc_upstream_ver}"
${PATCH} -p1 < "../mspgcc-${mspgcc_ver}/msp430-gcc-${gcc_upstream_ver}-${gcc_patch_ver}.patch"
)
[ -d "gdb-${gdb_upstream_ver_orig}" ] && rm -rf ./"gdb-${gdb_upstream_ver_orig}"
tar xzf "gdb-${gdb_upstream_ver}.tar.gz"
(
cd "gdb-${gdb_upstream_ver_orig}"
${PATCH} -p1 < "../mspgcc-${mspgcc_ver}/msp430-gdb-${gdb_upstream_ver_orig}-${gdb_patch_ver}.patch"
)
[ -d "msp430mcu-${mcu_ver}" ] && rm -rf ./"msp430mcu-${mcu_ver}"
tar xjf "msp430mcu-${mcu_ver}.tar.bz2"
[ -d "msp430-libc-${libc_ver}" ] && rm -rf ./"msp430-libc-${libc_ver}"
tar xjf "msp430-libc-${libc_ver}.tar.bz2"
echo '!!! lts patches'
if [ "${binutils_lts_patches}" ]
then
for p in ${binutils_lts_patches}
do
rm -f "msp430-binutils-${binutils_upstream_ver}-${binutils_patch_ver}-${p}.patch"
dl "${lts_patches_url}/msp430-binutils-${binutils_upstream_ver}-${binutils_patch_ver}-${p}.patch/download"
(
cd "binutils-${binutils_upstream_ver}"
${PATCH} -p1 < "../msp430-binutils-${binutils_upstream_ver}-${binutils_patch_ver}-${p}.patch"
)
done
fi
if [ "${gcc_lts_patches}" ]
then
for p in ${gcc_lts_patches}
do
dl "${lts_patches_url}/msp430-gcc-${gcc_upstream_ver}-${gcc_patch_ver}-${p}.patch/download"
(
cd "gcc-${gcc_upstream_ver}"
${PATCH} -p1 < "../msp430-gcc-${gcc_upstream_ver}-${gcc_patch_ver}-${p}.patch"
)
done
fi
if [ "${gdb_lts_patches}" ]
then
for p in ${gdb_lts_patches}
do
dl "${lts_patches_url}/msp430-gdb-${gdb_upstream_ver}-${gdb_patch_ver}-${p}.patch/download"
(
cd "gdb-${gdb_upstream_ver_orig}"
${PATCH} -p1 < "../msp430-gdb-${gdb_upstream_ver}-${gdb_patch_ver}-${p}.patch"
)
done
fi
if [ "${libc_lts_patches}" ]
then
for p in ${libc_lts_patches}
do
dl "${lts_patches_url}/msp430-libc-${libc_ver}-${p}.patch/download"
(
cd "msp430-libc-${libc_ver}"
${PATCH} -p1 < "../msp430-libc-${libc_ver}-${p}.patch"
)
done
fi
if [ "${mcu_lts_patches}" ]
then
for p in ${mcu_lts_patches}
do
dl "${lts_patches_url}/msp430mcu-${mcu_ver}-${p}.patch/download"
(
cd "msp430mcu-${mcu_ver}"
${PATCH} -p1 < "../msp430mcu-${mcu_ver}-${p}.patch"
)
done
fi
echo '!!! binutils configure'
mkdir -p BUILD/binutils
cd BUILD/binutils
"../../binutils-${binutils_upstream_ver}/configure" \
--disable-nls \
--target=msp430 \
--with-pkgversion="With patches: ${gcc_lts_patches}" \
--prefix="${PREFIX}"
echo '!!! binutils make'
${MAKE}
echo '!!! binutils check'
${MAKE} check-gas RUNTESTFLAGS=msp430.exp
echo '!!! binutils install'
${MAKE} install
cd ../../
mkdir -p BUILD/gcc
cd BUILD/gcc
echo '!!! gcc configure'
"../../gcc-${gcc_upstream_ver}/configure" ${GCC_CONFG_ARGS} \
--enable-languages="c,c++" \
--disable-nls \
--target=msp430 \
--prefix="${PREFIX}"
echo '!!! gcc make'
${MAKE}
echo '!!! gcc check'
${MAKE} check-gcc RUNTESTFLAGS=msp430.exp
echo '!!! gcc install'
${MAKE} install
cd ../../
cd "msp430-libc-${libc_ver}/src"
[ -d Build ] && rm -rf Build
echo '!!! libc make'
${MAKE} PREFIX="${PREFIX}"
echo '!!! libc install'
${MAKE} PREFIX="${PREFIX}" install
cd ../../
cd "msp430mcu-${mcu_ver}"
echo '!!! mcu install'
sh scripts/install.sh "${PREFIX}"
cd ../
mkdir -p BUILD/gdb
cd BUILD/gdb
echo '!!! gdb configure'
"../../gdb-${gdb_upstream_ver_orig}/configure" \
--disable-nls \
--target=msp430 \
--prefix="${PREFIX}"
echo '!!! gdb make'
${MAKE}
echo '!!! gdb install'
${MAKE} install
cd ../../
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment