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/ide/QtCreator/QtCreatorSetup.sh b/ide/QtCreator/QtCreatorSetup.sh
index e7a2fb8..c7158eb 100755
--- a/ide/QtCreator/QtCreatorSetup.sh
+++ b/ide/QtCreator/QtCreatorSetup.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,104 +290,127 @@ 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 "  --clean, -c             Delete project files.\n"
-  printf "  --wipe, -w              Delete project and .user files.\n"
-  printf "  --LightRing, -L         Create a project for the LightRing module.\n"
-  printf "  --PowerManagement, -P   Create a project for the PowerManagement module.\n"
-  printf "  --DiWheelDrive, -D      Create a project for the DiWheelDrive module.\n"
-  printf "  --All, -A               Create projects for all modules.\n"
-  printf "  --quit, -q              Quit the script.\n"
-  printf "  --log=<file>            Specify a log file.\n"
+  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [--LightRing] [--PowerManagement] [--DiWheelDrive] [-a|--all] [-q|--quit] [--log=<file>]\n"
+  printf "\n"
+  printf "options:  -h, --help\n"
+  printf "              Print this help text.\n"
+  printf "          -c, --clean\n"
+  printf "              Delete project files.\n"
+  printf "          -w, --wipe\n"
+  printf "              Delete project and .user files.\n"
+  printf "          --LightRing\n"
+  printf "              Create project for the LightRing module.\n"
+  printf "          --PowerManagement\n"
+  printf "              Create project for the PowerManagement module.\n"
+  printf "          --DiWheelDrive\n"
+  printf "              Create project for the DiWheelDrive module.\n"
+  printf "          -a, --all\n"
+  printf "              Create projects for all modules.\n"
+  printf "          -q, --quit\n"
+  printf "              Quit the script.\n"
+  printf "          --log=<file>\n"
+  printf "              Specify a log file.\n"
 }
 
-### read directory where to create/delete projects
-# arguments:
-#   - $1: variable to store the path to [required]
-# return: n/a
+### read directory where to create/delete projects #############################
+# Read the directory where to create/delete project files from user.
+#
+# usage:      getProjectDir <pathvar>
+# arguments:  <pathvar>
+#                 Variable to store the selected path to.
+# return:     n/a
+#
 function getProjectDir {
-  printLog "reading path for project files\n"
-  local amirobltdir="$(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/)"
-  local pojectdir=""
-  read -p "Path where to create/delete project files: " -i $amirobltdir -e projectdir
-  printLog "user selected path $(realpath $projectdir)\n"
-  eval $1="$(realpath $projectdir)"
+  printLog "reading path for project files from user...\n"
+  local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../Target/)
+  local input=""
+  read -p "Path where to create/delete project files: " -i $amirobltdir -e input
+  printLog "user selected path $(realpath $input)\n"
+  eval $1="$(realpath $input)"
 }
 
-### retrieves the ARM-NONE-EABI-GCC include directory
-# arguments:
-#   - $1: variable to store the path to [required]
-# return:
-#  -  0: no error
-#  - -1: error: arm-none-eabi-gcc not found
+### retrieves the ARM-NONE-EABI-GCC include directory ##########################
+# Retrieves the include directory of the currently set arm-none-eabi-gcc.
+#
+# usage:      retrieveGccIncludeDir <path>
+# arguments:  <path>
+#                 Variable to store the path to.
+# return:    0
+#                 No error or warning occurred.
+#            -1
+#                 Error: Command 'arm-none-eabi-gcc' not found.
+#
 function retrieveGccIncludeDir {
   # retrieve binary path or link
-  local binpath="$(which arm-none-eabi-gcc)"
+  local binpath=$(which arm-none-eabi-gcc)
   if [ -z "$binpath" ]; then
-    printError "arm-none-eabi-gcc not found\n"
+    printError "command 'arm-none-eabi-gcc' not found\n"
     return -1
-  fi
+  else 
 
-  # traverse any links
-  while [ -L "$binpath" ]; do
-    binpath=$(readlink $binpath)
-  done
-  printInfo "gcc-arm-none-eabi detected: $binpath\n"
+    # traverse any links
+    while [ -L "$binpath" ]; do
+      binpath=$(readlink $binpath)
+    done
+    printInfo "gcc-arm-none-eabi detected: $binpath\n"
 
-  # return include path
-  eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
+    # return include path
+    eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
 
-  return 0
+    return 0
+  fi
 }
 
-### delete project files
-# arguments:
-#  --path, -p <path>  path where to delete the project files
-#  --out, -o <var>    variable to store the path to
-#  --wipe, -w         delete .user files as well
+### delete project files #######################################################
+# Deletes all project files and optionally .user files, too.
+#
+# usage:      deleteProjects [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe]
+# arguments:  -p, --path <path>
+#                 Path where to delete the project files.
+#             -o, --out <var>
+#                 Variable to store the path to.
+#             -w, --wipe
+#                 Delete .user files as well.
 # return:
 #  -  0: no error
 #  -  1: warning: function aborted by user
 #  - -1: error: unexpected user input
 function deleteProjects {
-  # parse arguments
-  local arguments=$(getopt -l path:,out:,wipe -o p:o:w -- "$@")
-  if [ $? != 0 ]; then
-    printError "could not interprete arguments."
-    return -1
-  fi
-  eval set -- "$arguments"
-
   local projectdir=""
   local outvar=""
   local wipe=false
 
-  # handle command line arguments
-  while [ true ]; do
-    case $1 in
-      --path|-p)
-        projectdir="$2"; shift 2
-        ;;
-      --out|-o)
-        outvar=$2; shift 2
-        ;;
-      --wipe|-w)
-        wipe=true; shift 1
-        ;;
-      --) # end of options reached
-        shift; break
-        ;;
-      *) # sanity check (exit with error)
-        printError "unexpected argument: $1\n"; return 1
-        ;;
-    esac
+  # parse arguments
+  local otherargs=()
+  while [ $# -gt 0 ]; do
+    if ( parseIsOption $1 ); then
+      case "$1" in
+        -p=*|--path=*)
+          projectdir=$(realpath "${1#*=}"); shift 1;;
+        -p|--path)
+          projectdir=$(realpath "$2"); shift 2;;
+        -o=*|--out=*)
+          outvar=${1#*=}; shift 1;;
+        -o|--out)
+          outvar=$2; shift 2;;
+        -w|--wipe)
+          wipe=true; shift 1;;
+        *)
+          printError "invalid option: $1\n"; shift 1;;
+      esac
+    else
+      otherargs+=("$1")
+      shift 1
+    fi
   done
 
   # print message
@@ -440,46 +456,59 @@ function deleteProjects {
   return 0
 }
 
-### create LightRing project files
-# arguments:
-#  --path, -p <path>  path where to create the project files
-#  --out, -o <var>    variable to store the path to
-# return:
-#  -  0: no error
-#  -  1: warning: function aborted by user
-#  - -1: error: unexpected user input
+### create LightRing project files #############################################
+# Create project files for the LightRing module.
+#
+# usage:      createLightRingProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
+# arguments:  -p, --path <path>
+#                 Path where to create the project files.
+#             --gcc=<path>
+#                 Path to the GCC include directory.
+#             -o, --out <var>
+#                 Variable to store the path to.
+#             --gccout=<var>
+#                 Variable to store the path to the GCC include directory to.
+# return:     0
+#                 No error or warning occurred.
+#
 function createLightRingProject {
-  # parse arguments
-  local arguments=$(getopt -l path:,out: -o p:o: -- "$@")
-  if [ $? != 0 ]; then
-    printError "could not interprete arguments."
-    return -1
-  fi
-  eval set -- "$arguments"
-
   local projectdir=""
+  local gccincludedir=""
   local outvar=""
+  local gccoutvar=""
 
-  # handle command line arguments
-  while [ true ]; do
-    case $1 in
-      --path|-p)
-        projectdir="$2"; shift 2
-        ;;
-      --out|-o)
-        outvar=$2; shift 2
-        ;;
-      --) # end of options reached
-        shift; break
-        ;;
-      *) # sanity check (exit with error)
-        printError "unexpected argument: $1\n"; return 1
-        ;;
-    esac
+  # parse arguments
+  local otherargs=()
+  while [ $# -gt 0 ]; do
+    if ( parseIsOption $1 ); then
+      case "$1" in
+        -p=*|--path=*)
+          projectdir=$(realpath "${1#*=}"); shift 1;;
+        -p|--path)
+          projectdir=$(realpath "$2"); shift 2;;
+        --gcc=*)
+          gccincludedir=$(realpath "${1#*=}"); shift 1;;
+        --gcc)
+          gccincludedir=$(realpath "$2"); shift 2;;
+        -o=*|--out=*)
+          outvar=${1#*=}; shift 1;;
+        -o|--out)
+          outvar=$2; shift 2;;
+        --gccout=*)
+          gccoutvar=$(realpath "${1#*=}"); shift 1;;
+        --gccout)
+          gccoutvar=$(realpath "$2"); shift 2;;
+        *)
+          printError "invalid option: $1\n"; shift 1;;
+      esac
+    else
+      otherargs+=("$1")
+      shift 1
+    fi
   done
 
   # print message
-  printInfo "creating QtCreator project files for the LightRing module\n"
+  printInfo "creating QtCreator project files for the LightRing module...\n"
 
   # read project directory if required
   if [ -z "$projectdir" ]; then
@@ -487,10 +516,8 @@ function createLightRingProject {
   fi
 
   # retrieve gcc-arm-none-eabi include dir
-  local gccincludedir=""
-  retrieveGccIncludeDir gccincludedir
   if [ -z "$gccincludedir" ]; then
-    return -1
+    retrieveGccIncludeDir gccincludedir
   fi
 
   # create project files
@@ -515,54 +542,70 @@ function createLightRingProject {
     echo -e "" >> ${projectdir}/LightRing.creator
   fi
 
-  # store the path to the output variable, if required
+  # fill the output variables
   if [ ! -z "$outvar" ]; then
     eval $outvar="$projectdir"
   fi
+  if [ ! -z "$gccoutvar" ]; then
+    eval $gccoutvar="$gccincludedir"
+  fi
 
   return 0
 }
 
-### create PowerManagement project files
-# arguments:
-#  --path, -p <path>  path where to create the project files
-#  --out, -o <var>    variable to store the path to
-# return:
-#  -  0: no error
-#  -  1: warning: function aborted by user
-#  - -1: error: unexpected user input
+### create PowerManagement project files #######################################
+# Create project files for the PowerManagement module.
+#
+# usage:      createPowerManagementProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
+# arguments:  -p, --path <path>
+#                 Path where to create the project files.
+#             --gcc=<path>
+#                 Path to the GCC include directory.
+#             -o, --out <var>
+#                 Variable to store the path to.
+#             --gccout=<var>
+#                 Variable to store the path to the GCC include directory to.
+# return:     0
+#                 No error or warning occurred.
+#
 function createPowerManagementProject {
-  # parse arguments
-  local arguments=$(getopt -l path:,out: -o p:o: -- "$@")
-  if [ $? != 0 ]; then
-    printError "could not interprete arguments."
-    return -1
-  fi
-  eval set -- "$arguments"
-
   local projectdir=""
+  local gccincludedir=""
   local outvar=""
+  local gccoutvar=""
 
-  # handle command line arguments
-  while [ true ]; do
-    case $1 in
-      --path|-p)
-        projectdir="$2"; shift 2
-        ;;
-      --out|-o)
-        outvar=$2; shift 2
-        ;;
-      --) # end of options reached
-        shift; break
-        ;;
-      *) # sanity check (exit with error)
-        printError "unexpected argument: $1\n"; return 1
-        ;;
-    esac
+  # parse arguments
+  local otherargs=()
+  while [ $# -gt 0 ]; do
+    if ( parseIsOption $1 ); then
+      case "$1" in
+        -p=*|--path=*)
+          projectdir=$(realpath "${1#*=}"); shift 1;;
+        -p|--path)
+          projectdir=$(realpath "$2"); shift 2;;
+        --gcc=*)
+          gccincludedir=$(realpath "${1#*=}"); shift 1;;
+        --gcc)
+          gccincludedir=$(realpath "$2"); shift 2;;
+        -o=*|--out=*)
+          outvar=${1#*=}; shift 1;;
+        -o|--out)
+          outvar=$2; shift 2;;
+        --gccout=*)
+          gccoutvar=$(realpath "${1#*=}"); shift 1;;
+        --gccout)
+          gccoutvar=$(realpath "$2"); shift 2;;
+        *)
+          printError "invalid option: $1\n"; shift 1;;
+      esac
+    else
+      otherargs+=("$1")
+      shift 1
+    fi
   done
 
   # print message
-  printInfo "creating QtCreator project files for the PowerManagement module\n"
+  printInfo "creating QtCreator project files for the PowerManagement module...\n"
 
   # read project directory if required
   if [ -z "$projectdir" ]; then
@@ -570,16 +613,14 @@ function createPowerManagementProject {
   fi
 
   # retrieve gcc-arm-none-eabi include dir
-  local gccincludedir=""
-  retrieveGccIncludeDir gccincludedir
   if [ -z "$gccincludedir" ]; then
-    return -1
+    retrieveGccIncludeDir gccincludedir
   fi
 
   # create project files
   # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories)
   find $gccincludedir -type d > ${projectdir}/PowerManagement.includes
-  find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM3_STM32" >> ${projectdir}/PowerManagement.includes
+  find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/PowerManagement.includes
   find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM4_STM32F405_Power_Management_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/PowerManagement.includes
   # generate a file that specifies all files
   echo -n "" > ${projectdir}/PowerManagement.files
@@ -598,54 +639,70 @@ function createPowerManagementProject {
     echo -e "" >> ${projectdir}/PowerManagement.creator
   fi
 
-  # store the path to the output variable, if required
+  # fill the output variables
   if [ ! -z "$outvar" ]; then
     eval $outvar="$projectdir"
   fi
+  if [ ! -z "$gccoutvar" ]; then
+    eval $gccoutvar="$gccincludedir"
+  fi
 
   return 0
 }
 
-### create DiWheelDrive project files
-# arguments:
-#  --path, -p <path>  path where to create the project files
-#  --out, -o <var>    variable to store the path to
-# return:
-#  -  0: no error
-#  -  1: warning: function aborted by user
-#  - -1: error: unexpected user input
+### create DiWheelDrive project files ##########################################
+# Create project files for the DiWheelDrive module.
+#
+# usage:      createDiWheelDriveProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
+# arguments:  -p, --path <path>
+#                 Path where to create the project files.
+#             --gcc=<path>
+#                 Path to the GCC include directory.
+#             -o, --out <var>
+#                 Variable to store the path to.
+#             --gccout=<var>
+#                 Variable to store the path to the GCC include directory to.
+# return:     0
+#                 No error or warning occurred.
+#
 function createDiWheelDriveProject {
-  # parse arguments
-  local arguments=$(getopt -l path:,out: -o p:o: -- "$@")
-  if [ $? != 0 ]; then
-    printError "could not interprete arguments."
-    return -1
-  fi
-  eval set -- "$arguments"
-
   local projectdir=""
+  local gccincludedir=""
   local outvar=""
+  local gccoutvar=""
 
-  # handle command line arguments
-  while [ true ]; do
-    case $1 in
-      --path|-p)
-        projectdir="$2"; shift 2
-        ;;
-      --out|-o)
-        outvar=$2; shift 2
-        ;;
-      --) # end of options reached
-        shift; break
-        ;;
-      *) # sanity check (exit with error)
-        printError "unexpected argument: $1\n"; return 1
-        ;;
-    esac
+  # parse arguments
+  local otherargs=()
+  while [ $# -gt 0 ]; do
+    if ( parseIsOption $1 ); then
+      case "$1" in
+        -p=*|--path=*)
+          projectdir=$(realpath "${1#*=}"); shift 1;;
+        -p|--path)
+          projectdir=$(realpath "$2"); shift 2;;
+        --gcc=*)
+          gccincludedir=$(realpath "${1#*=}"); shift 1;;
+        --gcc)
+          gccincludedir=$(realpath "$2"); shift 2;;
+        -o=*|--out=*)
+          outvar=${1#*=}; shift 1;;
+        -o|--out)
+          outvar=$2; shift 2;;
+        --gccout=*)
+          gccoutvar=$(realpath "${1#*=}"); shift 1;;
+        --gccout)
+          gccoutvar=$(realpath "$2"); shift 2;;
+        *)
+          printError "invalid option: $1\n"; shift 1;;
+      esac
+    else
+      otherargs+=("$1")
+      shift 1
+    fi
   done
 
   # print message
-  printInfo "creating QtCreator project files for the DiWheelDrive module\n"
+  printInfo "creating QtCreator project files for the DiWheelDrive module...\n"
 
   # read project directory if required
   if [ -z "$projectdir" ]; then
@@ -653,10 +710,8 @@ function createDiWheelDriveProject {
   fi
 
   # retrieve gcc-arm-none-eabi include dir
-  local gccincludedir=""
-  retrieveGccIncludeDir gccincludedir
   if [ -z "$gccincludedir" ]; then
-    return -1
+    retrieveGccIncludeDir gccincludedir
   fi
 
   # create project files
@@ -681,93 +736,55 @@ function createDiWheelDriveProject {
     echo -e "" >> ${projectdir}/DiWheelDrive.creator
   fi
 
-  # store the path to the output variable, if required
+  # fill the output variables
   if [ ! -z "$outvar" ]; then
     eval $outvar="$projectdir"
   fi
+  if [ ! -z "$gccoutvar" ]; then
+    eval $gccoutvar="$gccincludedir"
+  fi
 
   return 0
 }
 
-### create project files for al modules
-# arguments:
-#  --path, -p <path>  path where to create the project files
-#  --out, -o <var>    variable to store the path to
-# return:
-#  -  0: no error
-#  -  1: warning: function aborted by user
-#  - -1: error: unexpected user input
+### create project files for al modules ########################################
+# Create project files for all modules.
+#
+# usage:      createAllProjects
+# arguments:  n/a
+# return:     0
+#                 No error or warning occurred.
+#
 function createAllProjects {
-  # parse arguments
-  local arguments=$(getopt -l path:,out: -o p:o: -- "$@")
-  if [ $? != 0 ]; then
-    printError "could not interprete arguments."
-    return -1
-  fi
-  eval set -- "$arguments"
+  # print message
+  printInfo "creating QtCreator project files for the DiWheelDrive module...\n"
 
+  # read project directory
   local projectdir=""
-  local outvar=""
-
-  # handle command line arguments
-  while [ true ]; do
-    case $1 in
-      --path|-p)
-        projectdir="$2"; shift 2
-        ;;
-      --out|-o)
-        outvar=$2; shift 2
-        ;;
-      --) # end of options reached
-        shift; break
-        ;;
-      *) # sanity check (exit with error)
-        printError "unexpected argument: $1\n"; return 1
-        ;;
-    esac
-  done
-
-  # print message
-  printInfo "creating QtCreator projects files for all modules\n"
+  getProjectDir projectdir
+  printInfo "files will be created in $projectdir\n"
 
-  # read project directory if required
-  if [ -z "$projectdir" ]; then
-    getProjectDir projectdir
-  fi
+  # retrieve gcc-arm-none-eabi include dir
+  retrieveGccIncludeDir gccincludedir
 
   # create projects
-  createLightRingProject --path="$projectdir"
-  createPowerManagementProject --path="$projectdir"
-  createDiWheelDriveProject --path="$projectdir"
-
-  # store the path to the output variable, if required
-  if [ ! -z "$outvar" ]; then
-    eval $outvar="$projectdir"
-  fi
+  createLightRingProject --path="$projectdir" --gcc="$gccincludedir"
+  createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir"
+  createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir"
 
   return 0
 }
 
-################################################################################
-# SCRIPT MAIN FUNCTION                                                         #
-################################################################################
-
-### main function of this script
-# arguments: see help text
-# return: error code
-#   - 0: no error
-#   - 1: error
+### main function of this script ###############################################
+# Creates, deletes and wipes QtCreator project files for the three AMiRo base modules.
+#
+# usage:      see function printHelp
+# arguments:  see function printHelp
+# return:     0
+#                 No error or warning ocurred.
+#
 function main {
-
-  # parse arguments
-  local arguments=$(getopt -l help,clean,wipe,LightRing,PowerManagement,DiWheelDrive,All,quit,log:,LOG:,noinfo -o hcwLPDAq -- "$@")
-  if [ $? != 0 ]; then
-    printError "could not interprete arguments."
-    exit 1
-  fi
-  eval set -- "$arguments"
-
-  # print welcome/info text if not suppressed
+# print welcome/info text if not suppressed
   if [[ $@ != *"--noinfo"* ]]; then
     printWelcomeText
   else
@@ -776,18 +793,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
@@ -802,87 +826,44 @@ function main {
     quitScript
   fi
 
-  # handle command line arguments
-  local projectfilesdir=""
-  while [ true ]; do
-    case $1 in
-      --help|-h) # already handled; ignore
-        shift 1;
-        ;;
-      --clean|-c)
-        if [ -z "$projectfilesdir" ]; then
-          deleteProjects --out=projectfilesdir
-        else
-          deleteProjects --path="$projectfilesdir"
-        fi
-        printf "\n"
-        shift 1
-        ;;
-      --wipe|-w)
-          if [ -z "$projectfilesdir" ]; then
-          deleteProjects --out=projectfilesdir
-        else
-          deleteProjects --wipe --path="$projectfilesdir"
-        fi
-        printf "\n"
-        shift 1
-        ;;
-      --LightRing|-L)
-        if [ -z "$projectfilesdir" ]; then
-          createLightRingProject --out=projectfilesdir
-        else
-          createLightRingProject --path="$projectfilesdir"
-        fi
-        printf "\n"
-        shift 1
-        ;;
-      --PowerManagement|-P)
-        if [ -z "$projectfilesdir" ]; then
-          createPowerManagementProject --out=projectfilesdir
-        else
-          createPowerManagementProject --path="$projectfilesdir"
-        fi
-        printf "\n"
-        shift 1
-        ;;
-      --DiWheelDrive|-D)
-        if [ -z "$projectfilesdir" ]; then
-          createDiWheelDriveProject --out=projectfilesdir
-        else
-          createDiWheelDriveProject --path="$projectfilesdir"
-        fi
-        printf "\n"
-        shift 1
-        ;;
-      --All|-A)
-        if [ -z "$projectfilesdir" ]; then
-          createAllProjects --out=projectfilesdir
-        else
-          createAllProjects --path="$projectfilesdir"
-        fi
-        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;;
+        -c|--clean)
+          deleteProjects; printf "\n"; shift 1;;
+        -w|--wipe)
+          deleteProjects --wipe; printf "\n"; shift 1;;
+        --LightRing)
+          createLightRingProject; printf "\n"; shift 1;;
+        --PowerManagement)
+          createPowerManagementProject; printf "\n"; shift 1;;
+        --DiWheelDrive)
+          createDiWheelDriveProject; printf "\n"; shift 1;;
+        -a|--all)
+          createAllProjects; 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
+# interactive menu
+  while ( true ); do
     # main menu info prompt and selection
     printInfo "QtCreator setup main menu\n"
     printf "Please select one of the following actions:\n"
@@ -893,35 +874,28 @@ function main {
     printf "  [D] - create a project for the DiWheelDrive module\n"
     printf "  [A] - create a project for all modules\n"
     printf "  [Q] - quit this setup\n"
-    readUserInput --num-chars=1 --options="CcWwLlPpDdAaQq" --out=userinput
+    local userinput=""
+    readUserInput "CcWwLlPpDdAaQq" userinput
     printf "\n"
 
     # evaluate user selection
-    case $userinput in
+    case "$userinput" in
       C|c)
-        deleteProjects; printf "\n"
-        ;;
+        deleteProjects; printf "\n";;
       W|w)
-        deleteProjects --wipe; printf "\n"
-        ;;
+        deleteProjects --wipe; printf "\n";;
       L|l)
-        createLightRingProject; printf "\n"
-        ;;
+        createLightRingProject; printf "\n";;
       P|p)
-        createPowerManagementProject; printf "\n"
-        ;;
+        createPowerManagementProject; printf "\n";;
       D|d)
-        createDiWheelDriveProject; printf "\n"
-        ;;
+        createDiWheelDriveProject; printf "\n";;
       A|a)
-        createAllProjects; printf "\n"
-        ;;
+        createAllProjects; 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
 
