Guest User

MSP430 Tool-Chain Build Script

a guest
May 26th, 2014
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.71 KB | None | 0 0
  1. #!/bin/bash
  2. ################################################################################
  3. # msp430_build.sh
  4. #
  5. # MSP430 Tool-Chain Build Script.
  6. #
  7. # Maintained By: Ryan Jacobs <[email protected]>
  8. #
  9. # May 24 -> Original creation.
  10. ################################################################################
  11.  
  12. # Global Variables
  13. INSTALL_PREFIX=/opt/msp430
  14. START_DIR="$PWD"
  15.  
  16. PATH="$PATH:$INSTALL_PREFIX"
  17.  
  18. ########################################
  19. # Error Checking
  20. ########################################
  21. function errors()
  22. {
  23.     if [ -d build_area ]; then
  24.         printf "Error: Directory 'build_area' already exists! Please delete this and retry.\n"
  25.         exit 1
  26.     fi
  27. }
  28.  
  29. ########################################
  30. # Download the Files
  31. ########################################
  32. function dl()
  33. {
  34.     pushd "$START_DIR"
  35.         mkdir -p dl
  36.         pushd dl
  37.             urls=(\
  38.                 'http://ftpmirror.gnu.org/gdb/gdb-7.2a.tar.bz2' \
  39.                 'http://www.netgull.com/gcc/releases/gcc-4.9.0/gcc-4.9.0.tar.bz2' \
  40.                 'ftp://ftp.kernel.org/pub/linux/devel/binutils/binutils-2.24.51.0.3.tar.xz'\
  41.                 'http://softlayer-dal.dl.sourceforge.net/project/mspdebug/mspdebug-0.22.tar.gz'\
  42.                 'http://iweb.dl.sourceforge.net/project/mspgcc/msp430mcu/msp430mcu-20130321.tar.bz2'\
  43.                 'http://iweb.dl.sourceforge.net/project/mspgcc/msp430-libc/msp430-libc-20120716.tar.bz2'\
  44.             )
  45.             for url in ${urls[@]}; do
  46.                 wget --continue --tries=1 "$url"
  47.  
  48.                 if [ $? -eq 0 ]; then
  49.                     printf "Successfully downloaded: %s.\n\n" "$url"
  50.                 else
  51.                     printf "Download failed: %s.\n\n" "$url"
  52.                     exit 1
  53.                 fi
  54.             done
  55.         popd
  56.     popd
  57. }
  58.  
  59. ########################################
  60. # Extract Everything
  61. ########################################
  62. function extract()
  63. {
  64.     pushd "$START_DIR"
  65.         mkdir -p build_area
  66.         pushd build_area
  67.             # Extract all of the tarballs
  68.             printf "\n"
  69.             parallel '\
  70.                printf "Extracting %s.\n" {};\
  71.                tar xf {};\
  72.            ' ::: ../dl/*tar*
  73.         popd
  74.     popd
  75. }
  76.  
  77. ########################################
  78. # Build Everything
  79. ########################################
  80. function build()
  81. {
  82.     pushd "$START_DIR/build_area"
  83.         mkdir -p binutils-2.24-msp430
  84.         mkdir -p gcc-4.9.0-msp430
  85.         mkdir -p gdb-7.2-msp430
  86.  
  87.         # Binutils
  88.         pushd binutils-2.24-msp430
  89.             ../binutils-2.24/configure --prefix="$INSTALL_PREFIX" --target=msp430-elf --program-prefix="msp430-"
  90.             make || {
  91.                 printf "\n\nError: compiling binutils-2.24\n"
  92.                 # We get this weird compile error and this seems to fix it
  93.                 printf "Trying this command: sed -i 's/),.*TRUE)/))/g' bfd/bfd.h\n\n"
  94.                 sed -i 's/),.*TRUE)/))/g' bfd/bfd.h
  95.                 sleep 5
  96.             }
  97.             make || {
  98.                 printf "\n\nError: compiling binutils-2.24\n"
  99.                 exit 1
  100.             }
  101.             # sudo make install
  102.         popd
  103.  
  104.         # GCC
  105.         pushd gcc-4.9.0-msp430
  106.             pushd ../gcc-4.9.0
  107.                 ./contrib/download_prerequisites
  108.             popd
  109.             ../gcc-4.9.0/configure --prefix="$INSTALL_PREFIX" --target=msp430-elf --enable-languages=c --program-prefix="msp430-"
  110.             make || {
  111.                 printf "\n\nError: compiling gcc-4.9.0\n"
  112.                 exit 1
  113.             }
  114.             # sudo make install
  115.         popd
  116.  
  117.         # GDB
  118.         pushd gdb-7.2-msp430
  119.             ../gdb-7.2/configure --prefix="$INSTALL_PREFIX" --target=msp430-elf --program-prefix="msp430-"
  120.             make || {
  121.                 printf "\n\nError: compiling gdb-7.2\n"
  122.                 exit 1
  123.             }
  124.             # sudo make install
  125.         popd
  126.  
  127.         # mspgcc-mcu files
  128.         pushd msp430mcu-20130321
  129.             # sudo MSP430MCU_ROOT=`pwd` ./scripts/install.sh "$INSTALL_PREFIX"
  130.         popd
  131.  
  132.         # mspgcc-libc files
  133.         pushd msp430-libc-20120716
  134.             ./configure
  135.             pushd src
  136.                 make || {
  137.                     printf "\n\nError: compiling msp430-libc-20120716\n"
  138.                     exit 1
  139.                 }
  140.                 # sudo make PREFIX="$INSTALL_PREFIX" install
  141.             popd
  142.         popd
  143.  
  144.         # mspdebug
  145.         pushd mspdebug-0.22
  146.             make || {
  147.                 printf "\n\nError: compiling mspdebug-0.22\n"
  148.                 exit 1
  149.             }
  150.             # sudo make install
  151.         popd
  152.     popd
  153. }
  154.  
  155. function install()
  156. {
  157.     pushd "$START_DIR/build_area"
  158.         ########################################
  159.         # Install Everything
  160.         ########################################
  161.         # Binutils
  162.         pushd binutils-2.24-msp430
  163.             sudo make install
  164.         popd
  165.  
  166.         # GCC
  167.         pushd gcc-4.9.0-msp430
  168.             sudo make install
  169.         popd
  170.  
  171.         # GDB
  172.         pushd gdb-7.2-msp430
  173.             sudo make install
  174.         popd
  175.  
  176.         # mspgcc-mcu files
  177.         pushd msp430mcu-20130321
  178.             sudo MSP430MCU_ROOT=`pwd` ./scripts/install.sh "$INSTALL_PREFIX"
  179.         popd
  180.  
  181.         # mspgcc-libc files
  182.         pushd msp430-libc-20120716
  183.                 sudo make PREFIX="$INSTALL_PREFIX" install
  184.         popd
  185.  
  186.         # mspdebug
  187.         pushd mspdebug-0.22
  188.                 sudo make install
  189.             popd
  190.         popd
  191.     popd
  192. }
  193.  
  194. ########################################
  195. # Main
  196. ########################################
  197. START_TIME=$(date)
  198.  
  199. errors && {
  200.     printf "\n****************************************************\n"
  201.     printf "* Done error checking! Now starting the downloads. *\n"
  202.     printf "****************************************************\n\n"
  203. }
  204.  
  205. dl && {
  206.     printf "\n*******************************************************\n"
  207.     printf "* Done downloading! Now starting to extract the files *\n"
  208.     printf "*******************************************************\n\n"
  209. }
  210.  
  211. extract && {
  212.     printf "\n********************************************\n"
  213.     printf "* Done extracting! Now starting to build.  *\n"
  214.     printf "********************************************\n\n"
  215. }
  216.  
  217. build && {
  218.     printf "\n*******************************************\n"
  219.     printf "* Done building! Now starting to install. *\n"
  220.     printf "*******************************************\n\n"
  221. }
  222.  
  223. install && {
  224.     printf "\n*******************************************\n"
  225.     printf "* Done installing!                        *\n"
  226.     printf "*******************************************\n\n"
  227. }
Advertisement
Add Comment
Please, Sign In to add comment