Make the scripts more generic.

Also, patch gcc sources so that gnattools are included.
2 files changed, 106 insertions(+), 37 deletions(-)

M gcc-build-script/build-binutils.sh
M gcc-build-script/build-gcc.sh
M gcc-build-script/build-binutils.sh +45 -12
@@ 1,21 1,54 @@ 
 #!/bin/bash
 
-BINUTILS=binutils-2.26.1
+BINUTILS_VERSION=2.26.1
+
+BINUTILS=binutils-${BINUTILS_VERSION}
 
 TOP=$HOME/work/samd-ada
 
 TARGET=arm-none-eabi
 PREFIX=$TOP/toolchain
 
-../../src/$BINUTILS/configure \
-	--target=$TARGET   \
-	--prefix=$PREFIX   \
-	--disable-nls      \
-	--enable-multilib \
-	--enable-interwork \
-	--with-gnu-as      \
-	--with-gnu-ld      \
-	--disable-libssp || exit 1
+fail()
+{
+	echo $@
+	exit 1
+}
+
+fetch_binutils()
+{
+	cd $TOP
+	mkdir -p distfiles
+	cd distfiles || fail "cd distfiles"
+	if [ \! -f ${BINUTILS}.tar.bz2 ]; then
+		wget ftp://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
+	fi
+	cd $TOP
+	if [ \! -d src/${BINUTILS} ]; then
+		mkdir -p src
+		cd src || fail "cd src"
+		tar jxf ../distfiles/${BINUTILS}.tar.bz2 || fail "binutils: tar jxf"
+	fi
+}
 
-make -j4 all && \
-make install
+build_binutils()
+{
+	cd $TOP
+	mkdir -p obj/binutils
+	cd obj/binutils || fail "binutils: cd obj"
+	../../src/$BINUTILS/configure \
+		--target=$TARGET   \
+		--prefix=$PREFIX   \
+		--disable-nls      \
+		--enable-multilib \
+		--enable-interwork \
+		--with-gnu-as      \
+		--with-gnu-ld      \
+		--disable-libssp || fail "binutils: configure"
+
+	make -j4 all || fail "binutils: make"
+	make install || fail "binutils: make install"
+}
+
+fetch_binutils
+build_binutils

          
M gcc-build-script/build-gcc.sh +61 -25
@@ 1,33 1,69 @@ 
-#!/bin/bash
+#!/bin/sh
 
-GCC_DIR=../../src/gcc-6.1.0/
+GCC_VERSION=6.1.0
+GCC=gcc-${GCC_VERSION}
+
+GCC_DIR=../src/${GCC}/
 
 TOP=$HOME/work/samd-ada
 
 TARGET=arm-none-eabi
 PREFIX=$TOP/toolchain
 
-$GCC_DIR/configure --prefix=$PREFIX \
-	--target=$TARGET --enable-languages=c,ada \
-	--disable-decimal-float \
-	--disable-libffi \
-	--disable-libgomp \
-	--disable-libmudflap \
-	--disable-libquadmath \
-	--disable-libssp \
-	--disable-libstdcxx-pch \
-	--disable-nls \
-	--disable-tls \
-	--disable-multilib \
-	--without-headers \
-	--without-newlib \
-	--disable-shared \
-	--disable-threads \
-	--enable-version-specific-runtime-libs \
-	--disable-libada \
-	--enable-interwork \
-	--with-cpu=cortex-m0plus --with-mode=thumb \
-	--with-float=soft \
-	&& make && make install
+# exit on any program error
+set -e
+
+fetch_gcc()
+{
+	cd $TOP
+	mkdir -p distfiles
+	cd distfiles
+	if [ \! -f ${GCC}.tar.bz2 ]; then
+		wget ftp://ftp.mpi-sb.mpg.de/pub/gnu/mirror/gcc.gnu.org/pub/gcc/releases/${GCC}/${GCC}.tar.bz2
+	fi
+	cd $TOP
+	if [ \! -d src/${GCC} ]; then
+		mkdir -p src
+		cd src
+		tar jxf ../distfiles/${GCC}.tar.bz2
+		cd ${GCC}
+		patch -p1 < $TOP/gcc-6.1.0-gnattools.diff
+	fi
+
+}
 
-exit $?
+build_gcc()
+{
+	export PATH=$PREFIX/bin:$PATH
+	cd $TOP
+	mkdir -p obj/gcc
+	cd obj/gcc
+	../../src/${GCC}/configure --prefix=$PREFIX \
+		--target=$TARGET --enable-languages=c,ada \
+		--disable-decimal-float \
+		--disable-libffi \
+		--disable-libgomp \
+		--disable-libmudflap \
+		--disable-libquadmath \
+		--disable-libssp \
+		--disable-libstdcxx-pch \
+		--disable-nls \
+		--disable-tls \
+		--disable-multilib \
+		--without-headers \
+		--without-newlib \
+		--disable-shared \
+		--disable-threads \
+		--enable-version-specific-runtime-libs \
+		--disable-libada \
+		--enable-interwork \
+		--with-cpu=cortex-m0plus --with-mode=thumb \
+		--with-float=soft
+	make
+	make install
+}
+
+fetch_gcc
+build_gcc
+
+