commit 0a42f07830784c218177e5300df757f46056da8c
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Thu Sep 28 15:34:42 2017 +0200

    Further enhancements to the bash scripts.
    Additional scripts for compiler configuration have been added.

diff --git a/setup.sh b/setup.sh
index de13c05..fe7211f 100755
--- a/setup.sh
+++ b/setup.sh
@@ -27,256 +27,249 @@
 # GENERIC FUNCTIONS                                                            #
 ################################################################################
 
-### print an error
-# arguments:
-#   - error string [required]
-# return: n/a
+### print an error message #####################################################
+# Prints a error <message> to standard output.
+#If variable 'LOG_FILE' is specified, the message is also appended to the given file.
+#
+# usage:      printError <message>
+# arguments:  <message>
+#                 Message string to print.
+# return:     n/a
+#
 function printError {
   local string="ERROR:   $1"
-
   # if a log file is specified
-  if [ ! -z $LOG_FILE ]; then
+  if [ -n "$LOG_FILE" ]; then
     printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
   fi
   printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2
 }
 
-### print a warning
-# arguments:
-#   - warning string [required]
-# return: n/a
+### print a warning message ####################################################
+# Prints a warning <message> to standard output.
+#If variable 'LOG_FILE' is specified, the message is also appended to the given file.
+#
+# usage:      printMessage <message>
+# arguments:  <message>
+#                 Message string to print.
+# return:     n/a
+#
 function printWarning {
   local string="WARNING: $1"
-
   # if a log file is specified
-  if [ ! -z $LOG_FILE ]; then
+  if [ -n "$LOG_FILE" ]; then
     printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
   fi
-  printf "$(tput setaf 3)>>> $string$(tput sgr 0)" 1>&2
+  printf "$(tput setaf 3)>>> $string$(tput sgr 0)"
 }
 
-### print an information text
-# arguments:
-#   - information string [required]
-# return: n/a
+### print an information message ###############################################
+# Prints an information <message> to standard output.
+#If variable 'LOG_FILE' is specified, the message is also appended to the given file.
+#
+# usage:      printInfo <message>
+# arguments:  <message>
+#                 Message string to print.
+# return:     n/a
+#
 function printInfo {
   local string="INFO:    $1"
-
   # if a log file is specified
-  if [ ! -z $LOG_FILE ]; then
+  if [ -n "$LOG_FILE" ]; then
     printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
   fi
-  printf "$(tput setaf 2)>>> $string$(tput sgr 0)" 1>&2
+  printf "$(tput setaf 2)>>> $string$(tput sgr 0)"
 }
 
-### print a message to the log file
-# arguments:
-#   - information string [required]
-# return: n/a
+### print a message to file ####################################################
+# Appends a <message> to a log file, specified by the variable 'LOG_FILE'.
+#
+# usage       printLog <message>
+# arguments:  <message>
+#                 Message string to print.
+# return:     n/a
+#
 function printLog {
   local string="LOG:     $1"
-
   # if a log file is specified
-  if [ ! -z $LOG_FILE ]; then
+  if [ -n "$LOG_FILE" ]; then
     printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
   fi
 }
 
-### exit the script normally
-# arguments: n/a
-# return: 0 (success)
+### exit the script normally ###################################################
+# Prints a delimiter and exits the script normally (returns 0).
+#
+# usage:      quitScript
+# arguments:  n/a
+# return:     0
+#                 No error or warning occurred.
+#
 function quitScript {
-  printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n"
-  printf "\n"
+  printLog "exiting $(realpath ${BASH_SOURCE[0]})\n"
   printf "######################################################################\n"
-
   exit 0
 }
 
-### read a user input
-# arguments:
-#   --numchars, -n  maximum number of characters to read
-#   --options, -o   possible chacters to select (only applies if numchars=1)
-#   --out, -e       output variable to store the user input to
-# return: error code
-#   -  0: no error
-#   - -1: error: invalid arguments
+### read a user input ##########################################################
+# Reads a single character user input from a set up <options> and stores it in
+# a given <return> variable.
+#
+# usage:      readUserInput <options> <return>
+# arguments:  <options>
+#                 String definiing the set of valid characters.
+#                 If the string is empty, the user can input any character.
+#             <return>
+#                 Variable to store the selected character to.
+# return:     n/a
+#
 function readUserInput {
-  # parse arguments
-  local arguments=$(getopt -l num-chars:,options:,out: -o n:o:e: -- "$@")
-  if [ $? != 0 ]; then
-    printError "could not interprete arguments."
-    return -1
-  fi
-  eval set -- "$arguments"
-
-  # evaluate arguments
-  local numchars=0
-  local options=""
-  local outvar=""
-  while [ true ]; do
-    case "$1" in
-      --num-chars|-n)
-        numchars=$2; shift 2
-        ;;
-      --options|-o)
-        options="$2"; shift 2
-        ;;
-      --out|-e)
-        outvar=$2; shift 2
-        ;;
-      --) # end of options reached
-        shift; break
-        ;;
-      *) # sanity check (return error)
-        printError "unexpected argument: $1\n"; return -1
-        ;;
-    esac
-  done
-
+  local input=""
   # read user input
-  local _userinput=""
-  while [ -z $_userinput ] || ( [ $numchars == 1 ] && [ ! -z "$options" ] && [[ ! $_userinput =~ ^["$options"]$ ]] ); do
-    if [ $numchars == 0 ]; then
-      read -p "your selection: " -e _userinput
-    else
-      read -p "your selection: " -n $numchars -e _userinput
-    fi
-    if [ -z $_userinput ] || ( [ $numchars == 1 ] && [ ! -z "$options" ] && [[ ! $_userinput =~ ^["$options"]$ ]] ); then
-      printWarning "[$_userinput] is no valid action\n"
+  while [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); do
+    read -p "your selection: " -n 1 -e input
+    if [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); then
+      printWarning "[$input] is no valid action\n"
     fi
   done
-  printLog "[$_userinput] has been selected\n"
-  if [ ! -z "$outvar" ]; then
-    eval $outvar="$_userinput"
-  fi
-
-  return 0
+  printLog "[$input] has been selected\n"
+  eval $2="$input"
 }
 
-### set the log file
-# arguments:
-#   --file, -f    name of file [required]
-#   --option, -o  option if file already exists [optional]
-#                 a: append
-#                 r: delete and restart
-#                 n: disable log
-#                 A: silent append (no message in the log file)
-# return: error code
-#   -  0: no error
-#   -  1: warning: file already exists
-#   -  2: warning: no file specified
-#   - -1: error: invalid arguments
-function setLogFile {
-  # parse arguments
-  local arguments=$(getopt -l file:,option: -o f:o: -- "$@")
-  if [ $? != 0 ]; then
-    printError "could not interprete arguments."
+### check whether argument is an option ########################################
+# Checks a <string> whether it is an option.
+# Options are defined to either start with '--' followed by any string, or
+# to start with a single '-' followed by a single character, or
+# to start with a single '-' followed by a single character, a '=' and any string.
+# Examples: '--option', '--option=arg', '-o', '-o=arg', '--'
+#
+# usage:      parseIsOption <string>
+# arguments:  <string>
+#                 A string to check whether it is an option.
+# return:     0
+#                 <string> is an option.
+#             -1
+#                 <string> is not an option.
+#
+function parseIsOption {
+  if [[ "$1" =~ ^-(.$|.=.*) ]] || [[ "$1" =~ ^--.* ]]; then
+    return 0
+  else
     return -1
   fi
-  eval set -- "$arguments"
+}
 
-  # evaluate arguments
-  local fname=""
+### set the log file ###########################################################
+# Sets a specified <infile> as log file and checks whether it already exists.
+# If so, the log may either be appended to the file, its content can be cleared,
+# or no log is generated at all.
+# The resulting path is stored in <outvar>.
+#
+# usage:      setLogFile [--option=<option>] [--quiet] <infile> <outvar>
+# arguments:  --option=<option>
+#                 Select what to do if <file> already exists.
+#                 Possible values are 'a', 'r' and 'n'.
+#                 - a: append
+#                 - r: delete and restart
+#                 - n: no log
+#                 If no option is secified but <file> exists, an interactive selection is provided.
+#             --quiet
+#                 Suppress all messages.
+#             <infile>
+#                 Path of the wanted log file.
+#             <outvar>
+#                 Variable to store the path of the log file to.
+# return:     0
+#                 No error or warning occurred.
+#             -1
+#                 Error: invalid input
+#
+function setLogFile {
+  local filepath=""
   local option=""
-  while [ true ]; do
-    case "$1" in
-      --file|f)
-        if [ ! -z $2 ]; then
-          fname="$(dirname $2)/$(basename $2)"
-        else
-          fname=""
-        fi
-        shift 2
-        ;;
-      --option|-o)
-        case $2 in
-          A)
-            option="A"
-            ;;
-          a)
-            option="a"
-            ;;
-          r)
-            option="r"
-            ;;
-          n)
-            option="n"
-            ;;
-          *) # sanity check (return error)
-            printError "unexpected argument: $1\n"; return -1
-            ;;
-        esac
-        shift 2
-        ;;
-      --) # end of options reached
-        shift; break
-        ;;
-      *) # sanity check (return error)
-        printError "unexpected argument: $1\n"; return -1
-        ;;
-    esac
+  local quiet=false
+
+  # parse arguments
+  local otherargs=()
+  while [ $# -gt 0 ]; do
+    if ( parseIsOption $1 ); then
+      case "$1" in
+        -o=*|--option=*)
+          option=${1#*=}; shift 1;;
+        -o*|--option*)
+          option="$2"; shift 2;;
+        -q|--quiet)
+          quiet=true; shift 1;;
+        *)
+          printError "invalid option: $1\n"; shift 1;;
+      esac
+    else
+      otherargs+=("$1")
+      shift 1
+    fi
   done
+  filepath=$(realpath ${otherargs[0]})
 
-  # if no log file was specified
-  if [ -z $fname ]; then
-    printWarning "no log file specified (no log will be genreated)\n"
-    LOG_FILE=""
-    return 2
   # if file already exists
-  elif [ -f $fname ]; then
+  if [ -e $filepath ]; then
     # if no option was specified, ask what to do
-    if [ -z $option ]; then
-      printWarning "log file ${fname} already esists\n"
-      printf "Options:\n"
+    if [ -z "$option" ]; then
+      printWarning "log file $filepath already esists\n"
+      local userinput=""
+      printf "Select what to do:\n"
       printf "  [A] - append log\n"
       printf "  [R] - restart log (delete existing file)\n"
       printf "  [N] - no log\n"
-      readUserInput --num-chars=1 --options="AaRrNn" --out=userinput
+      readUserInput "AaRrNn" userinput
       option=${userinput,,}
     fi
-
     # evaluate option
-    case $option in
-      A)
-        LOG_FILE=$(realpath $fname)
-        ;;
+    case "$option" in
       a)
-        printInfo "appending log to existing file\n"
-        LOG_FILE=$(realpath $fname)
-        printf "\n" >> $LOG_FILE
-        printf "######################################################################\n" >> $LOG_FILE
-        printf "\n" >> $LOG_FILE
+        if [ $quiet = false ]; then
+          printInfo "appending log to $filepath\n"
+        fi
+        printf "\n" >> $filepath
+        printf "######################################################################\n" >> $filepath
+        printf "\n" >> $filepath
         ;;
       r)
-        printInfo "old log file deleted, starting clean\n"
-        LOG_FILE=$(realpath $fname)
-        rm $LOG_FILE
+        echo -n "" > $filepath
+        if [ $quiet = false ]; then
+          printInfo "content of $filepath wiped\n"
+        fi
         ;;
       n)
-        printInfo "no log file will be generated\n"
-        LOG_FILE=""
+        if [ $quiet = false ]; then
+          printInfo "no log file will be generated\n"
+        fi
+        filepath=""
         ;;
       *) # sanity check (return error)
-        printError "unexpected argument: $1\n"; return -1
-        ;;
+        printError "unexpected argument: $option\n"; return -1;;
     esac
-
-    return 1
   else
-    printInfo "log file set to $(realpath $fname)\n"
-    LOG_FILE=$(realpath $fname)
-    return 0
+    if [ $quiet = false ]; then
+      printInfo "log file set to $filepath\n"
+    fi
   fi
+
+  eval ${otherargs[1]}="$filepath"
+
+  return 0
 }
 
 ################################################################################
 # SPECIFIC FUNCTIONS                                                           #
 ################################################################################
 
-### print welcome text
-# arguments: n/a
-# return: n/a
+### print welcome text #########################################################
+# Prints a welcome message to standard out.
+#
+# usage:      printWelcomeText
+# arguments:  n/a
+# return:     n/a
+#
 function printWelcomeText {
   printf "######################################################################\n"
   printf "#                                                                    #\n"
@@ -297,38 +290,71 @@ function printWelcomeText {
   printf "######################################################################\n"
 }
 
-### print help text
-# arguments: n/a
-# return: n/a
+### print help #################################################################
+# Prints a help text to standard out.
+#
+# usage:      printHelp
+# arguments:  n/a
+# return:     n/a
+#
 function printHelp {
   printInfo "printing help text\n"
-  printf "usage:  $(basename ${BASH_SOURCE[0]}) [options]\n"
-  printf "options:\n"
-  printf "  --help, -h        Print this help text.\n"
-  printf "  --stm32flash, -f  Run stm32flash tool setup.\n"
-  printf "  --SerialBoot, -s  Run SerialBoot tool setup.\n"
-  printf "  --IDE, -e         Enter IDE setup.\n"
-  printf "  --quit, -q        Quit the script.\n"
-  printf "  --log=<file>      Specify a log file.\n"
+  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [-f|--stm32flash] [-s|--SerialBoot] [-e|--IDE] [-c|--compiler] [-q|--quit] [--log=<file>]\n"
+  printf "\n"
+  printf "options:  -h, --help\n"
+  printf "              Print this help text.\n"
+  printf "          -f, --stm32flash\n"
+  printf "              Run st,32flash tool setup.\n"
+  printf "          -s, --SerialBoot\n"
+  printf "              Run SerialBoot tool setup.\n"
+  printf "          -e, --IDE\n"
+  printf "              Enter IDE setup.\n"
+  printf "          -c, --compiler\n"
+  printf "              Enter compiler setup.\n"
+  printf "          -q, --quit\n"
+  printf "              Quit the script.\n"
+  printf "          --log=<file>\n"
+  printf "              Specify a log file.\n"
 }
 
-### enter bootloader setup
-# arguments n/a
-# return:
-#  -  0: no error
-#  -  1: warning: function aborted by user
-#  - -1: error: unexpected user input
+### stm32flash tool setup ######################################################
+# Fetches the source code for the stm32flash tool and builds the binary.
+# If the tool was already initialized, it can be wiped and rebuilt.
+#
+# usage:      stm32flashSetup
+# arguments:  n/a
+# return:     0
+#                 No error or warning occurred.
+#             1
+#                 Warning: Setup aborted by user.
+#             -1
+#                 Error: Unexpected user input.
+#
 function stm32flashSetup {
   local stm32flashdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/Host/Source/stm32flash/
+  local userdir=$(pwd)
 
   # if the stm32flash folder is not empty
   if [ ! -z "$(ls -A $stm32flashdir)" ]; then
-    printWarning "$(realpath $stm32flashdir) is not empty. Delete and reinitialize? [y/n]\n"
-    readUserInput --num-chars=1 --options="YyNn" --out=userinput
-    case $userinput in
+    printWarning "$stm32flashdir is not empty. Delete and reinitialize? [y/n]\n"
+    local userinput=""
+    readUserInput "YyNn" userinput
+    case "$userinput" in
       Y|y)
-        printInfo "wiping $stm32flashdir\n"
+        printInfo "wiping ${stm32flashdir}...\n"
+        # checkout base commit and delete all local branches
+        git submodule update --force --checkout $stm32flashdir | tee -a $LOG_FILE
+        cd $stm32flashdir
+        local git_branches=($(git for-each-ref --format="%(refname)"))
+        for branch in $git_branches ; do
+          if [[ $branch = *"heads/"* ]]; then
+            git branch -D ${branch##*/} | tee -a $LOG_FILE
+          fi
+        done
+        cd $userdir
+        # deinit stm32flash submodule and delete any remaining files
         git submodule deinit -f $stm32flashdir 2>&1 | tee -a $LOG_FILE
+        rm -rf $stm32flashdir/*
         ;;
       N|n)
         printWarning "stm32flash setup aborted by user\n"
@@ -342,7 +368,7 @@ function stm32flashSetup {
   fi
 
   # initialize submodule
-  printInfo "initializing stm32flash submodule\n"
+  printInfo "initializing stm32flash submodule...\n"
   git submodule update --init $stm32flashdir 2>&1 | tee -a $LOG_FILE
 
   # build the stm32flash tool
@@ -355,22 +381,31 @@ function stm32flashSetup {
   return 0
 }
 
-### enter SerialBoot setup
-# arguments n/a
-# return:
-#  -  0: no error
-#  -  1: warning: function aborted by user
-#  - -1: error: unexpected user input
+### SerialBoot tool setup ######################################################
+# Builds the SerialBoot tool.
+# If the tool was built before, it can be deleted and rebuilt.
+#
+# usage:      serialBootSetup
+# arguments:  n/a
+# return:     0
+#                 No errort or warning occurred.
+#             1
+#                 Warning: Setup aborted by user.
+#             -1
+#                 Error: Unexpected user input.
+#
 function serialBootSetup {
   local serialbootdir=$(dirname $(realpath ${BASH_SOURCE[0]}))/Host/Source/SerialBoot/
+  local userdir=$(pwd)
 
   # if a build folder already exists
   if [ -d "${serialbootdir}/build/" ]; then
     printWarning "SerialBoot has been built before. Delete and rebuild? [y/n]\n"
-    readUserInput --num-chars=1 --options="YyNn" --out=userinput
-    case $userinput in
+    local userinput=""
+    readUserInput "YyNn" userinput
+    case "$userinput" in
       Y|y)
-        printInfo "deleting ${serialbootdir}build/\n"
+        printInfo "deleting ${serialbootdir}build/...\n"
         rm -rf "${serialbootdir}build/"
         ;;
       N|n)
@@ -385,49 +420,60 @@ function serialBootSetup {
   fi
 
   # build SerialBoot
-  printInfo "compiling SerialBoot\n"
-  local userdir=${PWD}
-  mkdir "${serialbootdir}build/"
-  cd "${serialbootdir}build/"
+  printInfo "compiling SerialBoot...\n"
+  mkdir ${serialbootdir}build/
+  cd ${serialbootdir}build/
   cmake .. 2>&1 | tee -a $LOG_FILE
   make 2>&1 | tee -a $LOG_FILE
-  cd "$userdir"
+  cd $userdir
 
   return 0
 }
 
-### enter IDE setup
-# arguments n/a
-# return: n/a
+### IDE setup ##################################################################
+# Enter the IDE setup.
+#
+# usage:      ideSetup
+# arguments:  n/a
+# return:     n/a
+#
 function ideSetup {
-  printInfo "entering ideSetup setup\n"
+  printInfo "entering IDE setup\n"
   printf "\n"
-  if [ -z $LOG_FILE ]; then
-    $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/setup_IDE.sh --noinfo
+  if [ -z "$LOG_FILE" ]; then
+    $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/idesetup.sh --noinfo
   else
-    $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/setup_IDE.sh --LOG="$LOG_FILE" --noinfo
+    $(dirname $(realpath ${BASH_SOURCE[0]}))/ide/idesetup.sh --LOG="$LOG_FILE" --noinfo
   fi
 }
 
-################################################################################
-# SCRIPT MAIN FUNCTION                                                         #
-################################################################################
-
-### main function of this script
-# arguments: see help text
-# return: error code
-#   - 0: no error
-#   - 1: error
-function main {
-
-  # parse arguments
-  local arguments=$(getopt -l help,stm32flash,SerialBoot,IDE,quit,log:,LOG:,noinfo -o hfseq -- "$@")
-  if [ $? != 0 ]; then
-    printError "could not interprete arguments."
-    exit 1
+### compiler setup #############################################################
+# Enter the compiler setup.
+#
+# usage:      compilerSetup
+# arguments:  n/a
+# return:     n/a
+#
+function compilerSetup {
+  printInfo "entering IDE setup\n"
+  printf "\n"
+  if [ -z "$LOG_FILE" ]; then
+    $(dirname $(realpath ${BASH_SOURCE[0]}))/compiler/compilersetup.sh --noinfo
+  else
+    $(dirname $(realpath ${BASH_SOURCE[0]}))/compiler/compilersetup.sh --LOG="$LOG_FILE" --noinfo
   fi
-  eval set -- "$arguments"
+}
 
+### main function of this script ###############################################
+# A setup to initialize dependencies, setup IDE projects and configure the
+# compiler setup.
+#
+# usage:      see function printHelp
+# arguments:  see function printHelp
+# return:     0
+#                 No error or warning occurred.
+#
+function main {
   # print welcome/info text if not suppressed
   if [[ $@ != *"--noinfo"* ]]; then
     printWelcomeText
@@ -437,18 +483,25 @@ function main {
   printf "\n"
 
   # set log file if specified
-  if [[ $@ == *--log* || $@ == *--LOG* ]]; then
+  if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then
     # get the parameter (file name)
     local cmdidx=1
-    while [ "${!cmdidx}" != "--log" ] && [ "${!cmdidx}" != "--LOG" ]; do
+    while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do
       cmdidx=$[cmdidx + 1]
     done
-    local filenameidx=$[cmdidx + 1]
+    local cmd="${!cmdidx}"
+    local logfile=""
+    if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then
+      logfile=${cmd#*=}
+    else
+      local filenameidx=$((cmdidx + 1))
+      logfile="${!filenameidx}"
+    fi
     # optionally force silent appending
-    if [ "${!cmdidx}" == "--LOG" ]; then
-      setLogFile --file="${!filenameidx}" --option=A
+    if [[ "$cmd" = "--LOG"* ]]; then
+      setLogFile --option=a --quiet "$logfile" LOG_FILE
     else
-      setLogFile --file="${!filenameidx}"
+      setLogFile "$logfile" LOG_FILE
       printf "\n"
     fi
   fi
@@ -463,71 +516,66 @@ function main {
     quitScript
   fi
 
-  # handle command line arguments
-  while [ true ]; do
-    case $1 in
-      --help|-h) # already handled; ignore
-        shift 1;
-        ;;
-      --stm32flash|-f)
-        stm32flashSetup; printf "\n"; shift 1
-        ;;
-      --SerialBoot|-s)
-        serialBootSetup; printf "\n"; shift 1
-        ;;
-      --IDE|-e)
-        IdeSetup; printf "\n"; shift 1;
-        ;;
-      --quit|-q)
-        quitScript
-        ;;
-      --log|--LOG) # already handled; ignore
-        shift 2
-        ;;
-      --noinfo) # already processed; ignore
-        shift 1
-        ;;
-      --) # end of options reached
-        shift; break
-        ;;
-      *) # sanity check (exit with error)
-        printError "unexpected argument: $1\n"; exit -1
-        ;;
-    esac
+  # parse arguments
+  local otherargs=()
+  while [ $# -gt 0 ]; do
+    if ( parseIsOption $1 ); then
+      case "$1" in
+        -h|--help) # already handled; ignore
+          shift 1;;
+        -f|--stm32flash)
+          stm32flashSetup; printf "\n"; shift 1;;
+        -s|--SerialBoot)
+          serialBootSetup; printf "\n"; shift 1;;
+        -e|--IDE)
+          ideSetup; printf "\n"; shift 1;;
+        -c|--compiler)
+          compilerSetup; printf "\n"; shift 1;;
+        -q|--quit)
+          quitScript; shift 1;;
+        --log=*|--LOG=*) # already handled; ignore
+          shift 1;;
+        --log|--LOG) # already handled; ignore
+          shift 2;;
+        --noinfo) # already handled; ignore
+          shift 1;;
+        *)
+          printError "invalid option: $1\n"; shift 1;;
+      esac
+    else
+      otherargs+=("$1")
+      shift 1
+    fi
   done
 
   # interactive menu
-  while [ true ]; do
+  while ( true ); do
     # main menu info prompt and selection
-    printInfo "AMiRo-BLT main menu\n"
+    printInfo "AMiRo-BLT setup main menu\n"
     printf "Please select one of the following actions:\n"
     printf "  [F] - get and build stm32flash tool\n"
     printf "  [S] - build SerialBoot tool\n"
     printf "  [E] - IDE project setup\n"
+    printf "  [C] - enter compiler setup\n"
     printf "  [Q] - quit this setup\n"
-    readUserInput --num-chars=1 --options="FfSsEeQq" --out=userinput
+    local userinput=""
+    readUserInput "FfSsEeCcQq" userinput
     printf "\n"
 
     # evaluate user selection
-    case $userinput in
-      I|i)
-        projectInitialization; printf "\n"
-        ;;
+    case "$userinput" in
       F|f)
-        stm32flashSetup; printf "\n"
-        ;;
+        stm32flashSetup; printf "\n";;
       S|s)
-        serialBootSetup; printf "\n"
-        ;;
+        serialBootSetup; printf "\n";;
       E|e)
-        ideSetup; printf "\n"
-        ;;
+        ideSetup; printf "\n";;
+      C|c)
+        compilerSetup; printf "\n";;
       Q|q)
-        quitScript
-        ;;
+        quitScript;;
       *) # sanity check (exit with error)
-        printError "unexpected argument: $userinput\n"; exit -1
-        ;;
+        printError "unexpected argument: $userinput\n";;
     esac
   done
 
@@ -540,166 +588,3 @@ function main {
 
 main "$@"
 
-
-## initial info text (can be disabled with 'no_info' as last argument)
-#if [[ ! ${!#} = "no_info" ]]; then
-#  printf "######################################################################\n"
-#  printf "#                                                                    #\n"
-#  printf "#                  Welcome to the AMiRo-BLT setup!                   #\n"
-#  printf "#                                                                    #\n"
-#  printf "######################################################################\n"
-#  printf "#                                                                    #\n"
-#  printf "# Copyright (c) 2016..2017  Thomas Schöpping                         #\n"
-#  printf "#                                                                    #\n"
-#  printf "# This is free software; see the source for copying conditions.      #\n"
-#  printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n"
-#  printf "# A PARTICULAR PURPOSE. The development of this software was         #\n"
-#  printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction  #\n"
-#  printf "# Technology. The Excellence Cluster EXC 227 is a grant of the       #\n"
-#  printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n"
-#  printf "# Excellence Initiative.                                             #\n"
-#  printf "#                                                                    #\n"
-#  printf "######################################################################\n"
-#  printf "\n"
-#fi
-#
-## initialization of variables
-#ARG_IDX=1
-#USER_INPUT=${!ARG_IDX}
-#
-#while [[ ! $USER_INPUT =~ ^[Ee]$ ]]; do
-#
-#  # main menu info prompt and selection
-#  printf "AMiRo-BLT setup\n"
-#  printf "===============\n"
-#  printf "\n"
-#  if [[ -z $USER_INPUT || $USER_INPUT == "no_info" ]]; then
-#    printf "Please select one of the following actions:\n"
-#    printf "    [F] - stm32flash flashing tool setup\n"
-#    printf "    [S] - SerialBoot flashing tool setup\n"
-#    printf "    [Q] - setup QtCreator projects\n"
-#    printf "    [E] - exit this setup\n"
-#
-#    while [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; do
-#      read -p "your selection: " -n 1 -e USER_INPUT
-#      if [[ ! $USER_INPUT =~ ^[FfSsQqEe]$ ]]; then
-#        printf "[%s] is no valid action. \n" $USER_INPUT
-#      fi
-#    done
-#
-#    printf "\n"
-#    printf "######################################################################\n"
-#    printf "\n"
-#  fi
-#
-#  # action selection
-#  case $USER_INPUT in
-#
-#    # stm32flash setup
-#    F|f)
-#      USER_DIR=${PWD}
-#      cd $(dirname ${BASH_SOURCE[0]})
-#
-#      # initialize submodule
-#      git submodule update --init ./Host/Source/stm32flash/
-#
-#      cd ./Host/Source/stm32flash/
-#      BUILD_STM32FLASH=true
-#
-#      # test for existing bonary
-#      if [ -f stm32flash ]; then
-#        printf "WARNING: stm32flash binary already exists.\n"
-#        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
-#        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
-#          BUILD_STM32FLASH=true
-#          make clean
-#        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
-#          BUILD_STM32FLASH=false
-#          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
-#        else
-#          BUILD_STM32FLASH=false
-#        fi
-#     fi
-#
-#      # build the tool if required
-#      if [ $BUILD_STM32FLASH = true ]; then
-#       make
-#      fi
-#
-#      cd $USER_DIR
-#      ;;
-#
-#    # SerailBoot setup
-#    S|s)
-#      # print setup header
-#      printf "SerialBoot setup\n"
-#      printf "================\n"
-#      printf "\n"
-#
-#      USER_DIR=${PWD}
-#      cd $(dirname ${BASH_SOURCE[0]})/Host/Source/SerialBoot/
-#      BUILD_SERIALBOOT=true
-#
-#      # test for existing binary
-#      if [ -f build/SerialBoot ]; then
-#        printf "WARNING: SerialBoot binary already exists.\n"
-#        read -p "Would you like to delete and rebuild it? [Y|n] " -n 1 -i "Y" -e USER_INPUT
-#        if [[ $USER_INPUT =~ ^[Yy]$ ]]; then
-#          BUILD_SERIALBOOT=true
-#          rm -rf build/
-#        elif [[ ! $USER_INPUT =~ ^[YyNn]$ ]]; then
-#          BUILD_SERIALBOOT=false
-#          printf "'%s' is no valid selection. Aborting setup.\n" $USER_INPUT
-#        else
-#          BUILD_SERIALBOOT=false
-#        fi
-#      fi
-#
-#      # build the tool if requested
-#      if [ $BUILD_SERIALBOOT = true ]; then
-#        mkdir build
-#        cd build
-#        cmake ..
-#        make
-#      fi
-#
-#      cd $USER_DIR
-#      ;;
-#
-#    # QtCreator setup
-#    Q|q)
-#      # calling the script with no arguments prints the help and returns
-#      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info
-#      printf "\n"
-#      # set deafult arguments and call the script again
-#      USER_INPUT="clean all"
-#      read -p "select commands: " -i "$USER_INPUT" -e USER_INPUT
-#      printf "\n"
-#      source $(dirname ${BASH_SOURCE[0]})/ide/QtCreator/QtCreatorSetup.sh no_info $USER_INPUT
-#      ;;
-#
-#    # exit
-#    E|e)
-#      break;
-#      ;;
-#
-#    # sanity check
-#    *)
-#      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
-#      printf "ERROR (${LINENO}): unexpected state; aborting script\n"
-#      printf "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
-#      printf "\n"
-#      exit
-#      ;;
-#
-#  esac
-#
-#  printf "\n"
-#  printf "######################################################################\n"
-#  printf "\n"
-#
-#  let ARG_IDX++
-#  USER_INPUT=${!ARG_IDX}
-#
-#done
-
