Fix wget invokation so that restarting downloads via -c works.
[fw/cortex-toolchain] / summon-arm-toolchain
index 413a1a152747522121b297b01df3950b3d79e87b..95da9dbc3ab346f07b08fdbcef3ec71e7f26b496 100755 (executable)
@@ -1,10 +1,11 @@
-#!/bin/sh
+#!/bin/bash
 # Written by Uwe Hermann <uwe@hermann-uwe.de>, released as public domain.
-# Modified by Piot Esden-Tempski <piotr@esden.net>, released as public domain.
+# Modified by Piotr Esden-Tempski <piotr@esden.net>, released as public domain.
 
-TARGET=arm-none-eabi                    # Or: TARGET=arm-none-eabi
-PREFIX=${HOME}/arm-none-eabi # Install location of your final toolchain
-PARALLEL="-j 5"                         # Or: PARALLEL=""
+TARGET=arm-elf                 # Or: TARGET=arm-none-eabi
+PREFIX=${HOME}/arm-elf         # Install location of your final toolchain
+PARALLEL=""                    # Or: PARALLEL="-j 5" for 4 CPU's
+DARWIN_OPT_PATH=/opt/local     # Path in which MacPorts or Fink is installed
 
 BINUTILS=binutils-2.19.1
 GCC=gcc-4.4.0
@@ -13,34 +14,50 @@ GDB=gdb-6.8
 LIBCMSIS=v1.10-2
 LIBSTM32=v3.0.0-1
 LIBSTM32USB=v3.0.1-1
+LIBOPENSTM32=master
+LIBSTM32_EN=0
+LIBOPENSTM32_EN=0
 
 export PATH="${PREFIX}/bin:${PATH}"
 
+case "$(uname)" in
+       Linux)
+       echo "Found Linux OS."
+       GCCFLAGS=
+       GDBFLAGS=
+       ;;
+       Darwin)
+       echo "Found Darwin OS."
+       GCCFLAGS="--with-gmp=${DARWIN_OPT_PATH} \
+                 --with-mpfr=${DARWIN_OPT_PATH} \
+                 -with-libiconv-prefix=${DARWIN_OPT_PATH}"
+        GDBFLAGS="--disable-werror"
+       ;;
+       *)
+       echo "Found unknown OS. Aborting!"
+       exit 1
+       ;;
+esac
+
 if [ ! -e sources ]; then
     mkdir sources
 fi
 
 cd sources
-if [ ! -e ${BINUTILS}.tar.bz2 ]; then
-       echo "Downloading binutils sources..."
-       wget -c http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
-fi
 
-if [ ! -e ${GCC}.tar.bz2 ]; then
-       echo "Downloading gcc sources..."
-       wget -c ftp://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.bz2
-fi
+echo "Downloading binutils sources..."
+wget -c http://ftp.gnu.org/gnu/binutils/${BINUTILS}.tar.bz2
 
-if [ ! -e ${NEWLIB}.tar.gz ]; then
-       echo "Downloading newlib sources..."
-       wget -c ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
-fi
+echo "Downloading gcc sources..."
+wget -c ftp://ftp.gnu.org/gnu/gcc/${GCC}/${GCC}.tar.bz2
 
-if [ ! -e ${GDB}.tar.bz2 ]; then
-       echo "Downloading gdb sources..."
-       wget -c ftp://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
-fi
+echo "Downloading newlib sources..."
+wget -c ftp://sources.redhat.com/pub/newlib/${NEWLIB}.tar.gz
+
+echo "Downloading gdb sources..."
+wget -c ftp://ftp.gnu.org/gnu/gdb/${GDB}.tar.bz2
 
+if [ ${LIBSTM32_EN} != 0 ]; then
 if [ ! -e libcmsis-${LIBCMSIS}.tar.bz2 ]; then
        echo "Cloning libcmsis sources..."
        git clone git://git.open-bldc.org/libcmsis.git
@@ -70,6 +87,19 @@ if [ ! -e libstm32usb-${LIBSTM32USB}.tar.bz2 ]; then
         cd ..
         rm -rf libstm32usb
 fi
+fi
+
+if [ ${LIBOPENSTM32_EN} != 0 ]; then
+if [ ! -e libopenstm32-${LIBOPENSTM32}.tar.bz2 ]; then
+       echo "Cloning libopenstm32 sources..."
+       git clone git://libopenstm32.git.sourceforge.net/gitroot/libopenstm32/libopenstm32
+        cd libopenstm32
+        git archive --format=tar --prefix=libopenstm32-${LIBOPENSTM32}/ ${LIBOPENSTM32} | \
+            bzip2 --stdout > ../libopenstm32-${LIBOPENSTM32}.tar.bz2
+        cd ..
+        rm -rf libopenstm32
+fi
+fi
 
 cd ..
 
@@ -128,7 +158,8 @@ if [ ! -e .${GCC}-boot.build ]; then
                       --disable-shared \
                       --with-gnu-as \
                       --with-gnu-ld \
-                      --disable-nls || exit
+                      --disable-nls \
+                     ${GCCFLAGS} || exit
     echo "******************************************************************"
     echo "* Building ${GCC}-boot"
     echo "******************************************************************"
@@ -197,7 +228,8 @@ if [ ! -e .${GCC}.build ]; then
                       --disable-shared \
                       --with-gnu-as \
                       --with-gnu-ld \
-                     --disable-nls || exit
+                     --disable-nls \
+                     ${GCCFLAGS} || exit
     echo "******************************************************************"
     echo "* Building ${GCC}"
     echo "******************************************************************"
@@ -226,7 +258,8 @@ if [ ! -e .${GDB}.build ]; then
     ../${GDB}/configure --target=${TARGET} \
                       --prefix=${PREFIX} \
                       --enable-interwork \
-                      --enable-multilib || exit
+                      --enable-multilib \
+                     ${GDBFLAGS} || exit
     echo "******************************************************************"
     echo "* Building ${GDB}"
     echo "******************************************************************"
@@ -243,6 +276,7 @@ if [ ! -e .${GDB}.build ]; then
     rm -rf build/* ${GDB}
 fi
 
+if [ ${LIBSTM32_EN} != 0 ]; then
 if [ ! -e .libcmsis-${LIBCMSIS}.build ]; then
     echo "******************************************************************"
     echo "* Unpacking libcmsis-${LIBCMSIS}"
@@ -308,3 +342,26 @@ if [ ! -e .libstm32usb-${LIBSTM32USB}.build ]; then
     touch .libstm32usb-${LIBSTM32USB}.build
     rm -rf libstm32usb-${LIBSTM32USB}
 fi
+fi
+
+if [ $LIBOPENSTM32_EN != 0 ]; then
+    echo "******************************************************************"
+    echo "* Unpacking libopenstm32-${LIBOPENSTM32}"
+    echo "******************************************************************"
+    tar xfvj sources/libopenstm32-${LIBOPENSTM32}.tar.bz2
+    cd libopenstm32-${LIBOPENSTM32}
+    echo "******************************************************************"
+    echo "* Building libopenstm32-${LIBOPENSTM32}"
+    echo "******************************************************************"
+    make PREFIX=${TARGET} DESTDIR=${PREFIX} || exit
+    echo "******************************************************************"
+    echo "* Installing libopenstm32-${LIBOPENSTM32}"
+    echo "******************************************************************"
+    make PREFIX=${TARGET} DESTDIR=${PREFIX} install || exit
+    cd ..
+    echo "******************************************************************"
+    echo "* Cleaning up libopenstm32-${LIBOPENSTM32}"
+    echo "******************************************************************"
+    touch .libopenstm32-${LIBOPENSTM32}.build
+    rm -rf libopenstm32-${LIBOPENSTM32}
+fi