commit 959f302eb0d808653f8b4fcfaf6c1725390a51ee
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Mon Dec 10 15:34:15 2018 +0100

    Drastically enhanced the QtCreator setup script.
    Now it is possible to generate project files for any module in a generic way as long as there is a functional Makefile in the module folder.

diff --git a/tools/ide/QtCreator/QtCreatorSetup.sh b/tools/ide/QtCreator/QtCreatorSetup.sh
index e62fbb0..d81dd83 100755
--- a/tools/ide/QtCreator/QtCreatorSetup.sh
+++ b/tools/ide/QtCreator/QtCreatorSetup.sh
@@ -303,22 +303,18 @@ function printWelcomeText {
 #
 function printHelp {
   printInfo "printing help text\n"
-  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [--LightRing] [--PowerManagement] [--DiWheelDrive] [-a|--all] [-q|--quit] [--log=<file>]\n"
+  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [--module=<module>] [-a|--all] [-c|--clean] [-w|--wipe] [-q|--quit] [--log=<file>]\n"
   printf "\n"
   printf "options:  -h, --help\n"
   printf "              Print this help text.\n"
+  printf "          --module=<module>\n"
+  printf "              Create project for a single module.\n"
+  printf "          -a, --all\n"
+  printf "              Create projects for all modules.\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"
@@ -374,97 +370,36 @@ function retrieveGccIncludeDir {
   fi
 }
 
-### delete project files #######################################################
-# Deletes all project files and optionally .user files, too.
+### detect available modules ###################################################
+# Detect all avalable modules supported by AMiRo-OS.
 #
-# 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 {
-  local projectdir=""
-  local outvar=""
-  local wipe=false
+# usage:      detectModules <modulearray>
+# arguments:  <modulearray>
+#                 Array variable to store all detected modules to.
+# return:     n/a
+#
+function detectModules {
+  local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../modules)
+  local modules_detected=()
 
-  # 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
+  # detect all available modules (via directories)
+  for dir in $(ls -d ${modulesdir}/*/); do
+    modules_detected[${#modules_detected[@]}]=$(basename $dir)
   done
 
-  # print message
-  if [ $wipe != true ]; then
-    printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n"
-  else
-    printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n"
-  fi
-
-  # read project directory if required
-  if [ -z "$projectdir" ]; then
-    getProjectDir projectdir
-  fi
-
-  # remove all project files
-  rm ${projectdir}/LightRing.includes 2>&1 | tee -a $LOG_FILE
-  rm ${projectdir}/PowerManagement.includes 2>&1 | tee -a $LOG_FILE
-  rm ${projectdir}/DiWheelDrive.includes 2>&1 | tee -a $LOG_FILE
-
-  rm ${projectdir}/LightRing.files 2>&1 | tee -a $LOG_FILE
-  rm ${projectdir}/PowerManagement.files 2>&1 | tee -a $LOG_FILE
-  rm ${projectdir}/DiWheelDrive.files 2>&1 | tee -a $LOG_FILE
-
-  rm ${projectdir}/LightRing.config 2>&1 | tee -a $LOG_FILE
-  rm ${projectdir}/PowerManagement.config 2>&1 | tee -a $LOG_FILE
-  rm ${projectdir}/DiWheelDrive.config 2>&1 | tee -a $LOG_FILE
-
-  rm ${projectdir}/LightRing.creator 2>&1 | tee -a $LOG_FILE
-  rm ${projectdir}/PowerManagement.creator 2>&1 | tee -a $LOG_FILE
-  rm ${projectdir}/DiWheelDrive.creator 2>&1 | tee -a $LOG_FILE
-
-  if [ $wipe == true ]; then
-    rm ${projectdir}/LightRing.creator.user 2>&1 | tee -a $LOG_FILE
-    rm ${projectdir}/PowerManagement.creator.user 2>&1 | tee -a $LOG_FILE
-    rm ${projectdir}/DiWheelDrive.creator.user 2>&1 | tee -a $LOG_FILE
-  fi
-
-  # store the path to the output variable, if required
-  if [ ! -z "$outvar" ]; then
-    eval $outvar="$projectdir"
-  fi
-
-  return 0
+  # set the output variable
+  eval "$1=(${modules_detected[*]})"
 }
 
-### create LightRing project files #############################################
-# Create project files for the LightRing module.
+### create project files for a single module ###################################
+# Create project files for a single module.
 #
-# usage:      createLightRingProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
-# arguments:  -p, --path <path>
+# usage:      createModuleProject <modules> [-m|--module=<module>] [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
+# arguments:  <modules>
+#                 Array containing all modules available.
+#             -m, --module <module>
+#                 Name (folder name) of the module for which project files shall be generated.
+#             -p, --path <path>
 #                 Path where to create the project files.
 #             --gcc=<path>
 #                 Path to the GCC include directory.
@@ -472,11 +407,24 @@ function deleteProjects {
 #                 Variable to store the path to.
 #             --gccout=<var>
 #                 Variable to store the path to the GCC include directory to.
+#                 If this optional arguments is absent, ths function will ask for user input.
 # return:     0
 #                 No error or warning occurred.
+#             1
+#                 Aborted by user.
+#             -1
+#                 No modules available.
+#             -2
+#                 The specified <module> could not be found.
+#             -3
+#                 Parsing the project for the specified module failed.
 #
-function createLightRingProject {
+function createModuleProject {
   local userdir=$(pwd)
+  local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../modules)
+  local modules=("${!1}")
+  local module=""
+  local moduleidx=""
   local projectdir=""
   local gccincludedir=""
   local outvar=""
@@ -487,6 +435,10 @@ function createLightRingProject {
   while [ $# -gt 0 ]; do
     if ( parseIsOption $1 ); then
       case "$1" in
+        -m=*|--module=*)
+          module="${1#*=}"; shift 1;;
+        -m|--module)
+          module="$2"; shift 2;;
         -p=*|--path=*)
           projectdir=$(realpath "${1#*=}"); shift 1;;
         -p|--path)
@@ -512,71 +464,178 @@ function createLightRingProject {
     fi
   done
 
-  # print message
-  printInfo "creating QtCreator project files for the LightRing module...\n"
+  # sanity check for the modules variable
+  if [ -z "${modules[*]}" ]; then
+    printError "no modules available\n"
+    return -1
+  fi
+
+  # select module
+  if [ -z $module ]; then
+    # list all available modules
+    printInfo "choose a module or type 'A' to abort:\n"
+    for (( idx=0; idx<${#modules[@]}; ++idx )); do
+      printf "%4u: %s\n" $(($idx + 1)) "${modules[$idx]}"
+    done
+    # read user input
+    printLog "read user selection\n"
+    local userinput=""
+    while [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#modules[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; do
+      read -p "your selection: " -e userinput
+      printLog "user selection: $userinput\n"
+      if [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#modules[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; then
+        printWarning "Please enter an integer between 1 and ${#modules[@]} or 'A' to abort.\n"
+      fi
+    done
+    if [[ "$userinput" =~ ^[Aa]$ ]]; then
+      printWarning "aborted by user\n"
+      return 1
+    fi
+    # store selection
+    moduleidx=$(($userinput - 1))
+    module="${modules[$moduleidx]}"
+    printf "\n"
+  else
+    # search all modules for the selected one
+    for (( idx=0; idx<${#modules[@]}; ++idx )); do
+      if [ "${modules[$idx]}" = "$module" ]; then
+        moduleidx=$idx
+        break
+      fi
+    done
+    # error if the module could not be found
+    if [ -z $moduleidx ]; then
+      printError "module ($module) not available\n"
+      return -2
+    fi
+  fi
 
   # read absolute project directory if required
   if [ -z "$projectdir" ]; then
     getProjectDir projectdir
+    printf "\n"
+  fi
+
+  # check for existing project files
+  if [ -f ${projectdir}/${module}.includes ] || [ -f ${projectdir}/${module}.files ] || [ -f ${projectdir}/${module}.config ] || [ -f ${projectdir}/${module}.creator ]; then
+    printWarning "The following files will be overwritten:\n"
+    if [ -f ${projectdir}/${module}.includes ]; then
+      printWarning "\t${module}.includes\n"
+    fi
+    if [ -f ${projectdir}/${module}.files ]; then
+      printWarning "\t${module}.files\n"
+    fi
+    if [ -f ${projectdir}/${module}.config ]; then
+      printWarning "\t${module}.config\n"
+    fi
+    if [ -f ${projectdir}/${module}.creator ]; then
+      printWarning "\t${module}.creator\n"
+    fi
+    local userinput=""
+    printInfo "Continue and overwrite? [y/n]\n"
+    readUserInput "YyNn" userinput
+    case "$userinput" in
+      Y|y)
+        ;;
+      N|n)
+        printWarning "Project generation for ${module} module aborted by user\n"
+        return 1
+        ;;
+      *)
+        printError "unexpected input: ${userinput}\n"; return -999;;
+    esac
+    printf "\n"
   fi
 
-  # retrieve absolute GCC include dir
+  # print message
+  printInfo "generating QtCreator project files for the $module module...\n"
+
+  # retrieve absolute GCC include path
   if [ -z "$gccincludedir" ]; then
     retrieveGccIncludeDir gccincludedir
   fi
 
-  # move to project directory
-  cd $projectdir
+  # change to project directory
+  cd "$projectdir"
 
-  # AMiRo-OS, ChibiOS, AMiRo-BLT and AMiRo-LLD relative root directories
+  # run make, but only run the GCC preprocessor and produce no binaries
   local amiroosrootdir=$(realpath $(dirname ${BASH_SOURCE[0]})/../../..)
-  local chibiosrootdir=$(realpath ${amiroosrootdir}/kernel/ChibiOS)
-  local amirobltrootdir=$(realpath ${amiroosrootdir}/bootloader/AMiRo-BLT)
-  local amirolldrootdir=$(realpath ${amiroosrootdir}/periphery-lld/AMiRo-LLD)
-
-  # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories)
-  find $gccincludedir -type d > ${projectdir}/LightRing.includes
-  echo $amiroosrootdir >> ${projectdir}/LightRing.includes
-  find $amiroosrootdir/modules -type d | grep -v "/doc\|/build\|/.dep\|/PowerManagement\|/DiWheelDrive" >> ${projectdir}/LightRing.includes
-  find $amiroosrootdir/core -type d >> ${projectdir}/LightRing.includes
-  find $amiroosrootdir/unittests -type d >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/abstractions/cmsis_os$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/ext/CMSIS/(include|ST/STM32F1xx)$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/oslib/(include|src)$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/ports/ARMCMx(/compilers/GCC)?$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/startup/ARMCMx/(compilers/GCC|devices/STM32F1xx)$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/(include|src)$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/lib/streams" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/osal/(lib|rt)$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/ports/(common/ARMCMx|STM32/(LLD/(CANv1|DACv1|DMAv1|EXTIv1|GPIOv1|I2Cv1|RTCv1|SDIOv1|SPIv1|TIMv1|USARTv1|USBv1|xWDGv1)|STM32F1xx))$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/license$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/os/rt/(include|src)$" >> ${projectdir}/LightRing.includes
-  find $chibiosrootdir -type d | grep -E "/test/(lib|rt/source/test)$" >> ${projectdir}/LightRing.includes
-  find $amirobltrootdir -type d | grep -E "/Target/Source/AMiRo$" >> ${projectdir}/LightRing.includes
-  echo "$(realpath ${amirolldrootdir}/..)" >> ${projectdir}/LightRing.includes
-  find $amirolldrootdir -type d | grep -v "/doc" >> ${projectdir}/LightRing.includes
-  # generate a file that specifies all files
-  echo -n "" > ${projectdir}/LightRing.files
-  for path in `cat ${projectdir}/LightRing.includes`; do
-    find $path -maxdepth 1 -type f \( ! -iname ".*" \) |
-      grep -Ev "^.*((/arm-none-eabi/)|(PowerManagement)|(DiWheelDrive)).*$" |
-      grep -E  "^.*(\.s|\.S|\.h|\.c|\.hpp|\.cpp|\.tpp|\.ld)$" |
-      grep -Ev "^${chibiosrootdir}/os/common/ext/CMSIS/ST/STM32F1xx/((stm32f1[^0x])|(stm32f10[^3])|(stm32f103[^x])|(stm32f103x[^e])).*$" |
-      grep -Ev "^${chibiosrootdir}/os/common/ext/CMSIS/include/((core_[^c])|(core_c[^m])|(core_cm[^3A-Za-z])|(cmsis_[^g])|(cmsis_g[^c]|(cmsis_gc[^c])))" |
-      grep -Ev "^${chibiosrootdir}/os/common/ports/ARMCMx/chcore_v[^7]m.*$" |
-      grep -Ev "^${chibiosrootdir}/os/common/ports/ARMCMx/compilers/GCC/.*_v[^7]m.*$" |
-      grep -Ev "^${chibiosrootdir}/os/common/startup/ARMCMx/compilers/GCC/.*_v[^7]m.*$" |
-      grep -Ev "^${chibiosrootdir}/os/hal/ports/STM32/STM32F1xx/.*f10[^3].*$" |
-      grep -Ev "^${amirobltrootdir}/Target/Source/AMiRo/helper.*$" >> ${projectdir}/LightRing.files;
+  local sourcefiles=()
+  local sourcefile=""
+  local capture_state="WAIT_FOR_INCLUDE_OR_COMPILING"
+  # capture all output from make and GCC and append the return value of make as last line
+  printInfo "processing project (this may take a while)...\n"
+  local rawout=$(make --directory ${amiroosrootdir}/modules/${module} --always-make USE_OPT="-v -E -H" OUTFILES="" 2>&1 && echo $?)
+  # check whether the make call was successfull
+  if [[ $(echo "${rawout}" | tail -n 1) != "0" ]]; then
+    printError "executing 'make' in module directory failed\n"
+    cd "$userdir"
+    return -3
+  fi
+  # extract file names from raw output
+  while read line; do
+    case $capture_state in
+      WAIT_FOR_INCLUDE_OR_COMPILING)
+        # lines stating included files look like:
+        # ... <../relative/path/to/file>
+        if [[ "$line" =~ ^\.+[[:blank:]].+\..+$ ]]; then
+          sourcefile=${line##* }
+          if [[ ! "$sourcefile" =~ ^/ ]]; then
+            sourcefile=$(realpath ${amiroosrootdir}/modules/${module}/${sourcefile})
+          fi
+          sourcefiles[${#sourcefiles[@]}]="$sourcefile"
+        # whenever the next source file is processed, a message appears like:
+        # Compining <filnemame>
+        elif [[ "$line" =~ ^Compiling[[:blank:]].+\..+$ ]]; then
+          printf "."
+          sourcefile=${line##* }
+          capture_state="WAIT_FOR_COMPILERCALL"
+        fi;;
+      WAIT_FOR_COMPILERCALL)
+        # wait for the actual call of the compiler to retrieve the full path to the source file
+        if [[ "$line" == *${sourcefile}* ]]; then
+          line="${line%%${sourcefile}*}${sourcefile}"
+          sourcefile=${line##* }
+          sourcefile=$(realpath ${amiroosrootdir}/modules/${module}/${line##* })
+          sourcefiles[${#sourcefiles[@]}]="$sourcefile"
+          capture_state="WAIT_FOR_INCLUDE_OR_COMPILING"
+        fi;;
+    esac
+  done <<< "${rawout}"
+  unset rawout
+  printf "\n"
+  # sort and remove duplicates
+  IFS=$'\n'; sourcefiles=($(sort --unique <<< "${sourcefiles[*]}")); unset IFS
+
+  # extract include paths
+  local includes=()
+  for source in ${sourcefiles[*]}; do
+    includes[${#includes[@]}]="$(dirname ${source})"
+  done
+  # sort and remove duplicates
+  IFS=$'\n'; includes=($(sort --unique <<< "${includes[*]}")); unset IFS
+
+  # generate the .files file, containing all source files
+  echo "" > ${projectdir}/${module}.includes
+  for inc in ${includes[*]}; do
+    echo "$inc" >> ${projectdir}/${module}.includes
+  done
+  # generate the .incldues file, containing all include paths
+  echo "" > ${projectdir}/${module}.files
+  for source in ${sourcefiles[*]}; do
+    # skip GCC files
+    if [[ ! "$source" =~ .*/gcc.* ]]; then
+      echo "$source" >> ${projectdir}/${module}.files
+    fi
   done
-  # generate a default project configuration file if none exists so far
-  if [ ! -f ${projectdir}/LightRing.config ]; then
-    echo "// Add predefined macros for your project here. For example:" > ${projectdir}/LightRing.config
-    echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/LightRing.config
+  # generate a default project configuration file if it doesn't exist yet
+  if [ ! -f ${projectdir}/${module}.config ]; then
+    echo "// Add predefined macros for your project here. For example:" > ${projectdir}/${module}.config
+    echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/${module}.config
   fi
-  # generate a default .creator file if none exists so far
-  if [ ! -f ${projectdir}/LightRing}.creator ]; then
-    echo "[general]" > ${projectdir}/LightRing.creator
+  # generate a default .creator file if it doesn't exist yet
+  if [ ! -f ${projectdir}/${module}.creator ]; then
+    echo "[general]" > ${projectdir}/${module}.creator
   fi
 
   # go back to user directory
@@ -593,11 +652,13 @@ function createLightRingProject {
   return 0
 }
 
-### create PowerManagement project files #######################################
-# Create project files for the PowerManagement module.
+### create project files for all modules #######################################
+# Create project files for all modules.
 #
-# usage:      createPowerManagementProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
-# arguments:  -p, --path <path>
+# usage:      createAllProjects <modules> [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
+# arguments:  <modules>
+#                 Array containing all modules available.
+#             -p, --path <path>
 #                 Path where to create the project files.
 #             --gcc=<path>
 #                 Path to the GCC include directory.
@@ -605,11 +666,14 @@ function createLightRingProject {
 #                 Variable to store the path to.
 #             --gccout=<var>
 #                 Variable to store the path to the GCC include directory to.
+#                 If this optional arguments is absent, ths function will ask for user input.
 # return:     0
 #                 No error or warning occurred.
+#             -1
+#                 No modules available.
 #
-function createPowerManagementProject {
-  local userdir=$(pwd)
+function createAllProjects {
+  local modules=("${!1}")
   local projectdir=""
   local gccincludedir=""
   local outvar=""
@@ -645,107 +709,60 @@ function createPowerManagementProject {
     fi
   done
 
-  # print message
-  printInfo "creating QtCreator project files for the PowerManagement module...\n"
+  # sanity check for the modules variable
+  if [ -z "${modules[*]}" ]; then
+    printError "no modules available\n"
+    return -1
+  fi
 
   # read absolute project directory if required
   if [ -z "$projectdir" ]; then
     getProjectDir projectdir
   fi
 
-  # retrieve absolute GCC include dir
+  # print message
+  printf "\n"
+  printInfo "generating QtCreator project files for all modules...\n"
+
+  # retrieve absolute GCC include path
   if [ -z "$gccincludedir" ]; then
     retrieveGccIncludeDir gccincludedir
   fi
 
-  # move to project directory
-  cd $projectdir
-
-  # AMiRo-OS, ChibiOS, AMiRo-BLT and AMiRo-LLD relative root directories
-  local amiroosrootdir=$(realpath $(dirname ${BASH_SOURCE[0]})/../../..)
-  local chibiosrootdir=$(realpath ${amiroosrootdir}/kernel/ChibiOS)
-  local amirobltrootdir=$(realpath ${amiroosrootdir}/bootloader/AMiRo-BLT)
-  local amirolldrootdir=$(realpath ${amiroosrootdir}/periphery-lld/AMiRo-LLD)
-
-  # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories)
-  find $gccincludedir -type d > ${projectdir}/PowerManagement.includes
-  echo $amiroosrootdir >> ${projectdir}/PowerManagement.includes
-  find $amiroosrootdir/modules -type d | grep -v "/doc\|/build\|/.dep\|/LightRing\|/DiWheelDrive" >> ${projectdir}/PowerManagement.includes
-  find $amiroosrootdir/core -type d >> ${projectdir}/PowerManagement.includes
-  find $amiroosrootdir/unittests -type d >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/abstractions/cmsis_os$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/ext/CMSIS/(include|ST/STM32F4xx)$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/oslib/(include|src)$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/ports/ARMCMx(/compilers/GCC)?$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/startup/ARMCMx/(compilers/GCC|devices/STM32F4xx)$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/(include|src)$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/lib/streams" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/osal/(lib|rt)$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/ports/(common/ARMCMx|STM32/(LLD/(ADCv2|CANv1|DACv1|DMAv2|EXTIv1|GPIOv2|I2Cv1|MACv1|OTGv1|RTCv2|SDIOv1|SPIv1|TIMv1|USARTv1|USBv1|xWDGv1)|STM32F4xx))$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/license$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/os/rt/(include|src)$" >> ${projectdir}/PowerManagement.includes
-  find $chibiosrootdir -type d | grep -E "/test/(lib|rt/source/test)$" >> ${projectdir}/PowerManagement.includes
-  find $amirobltrootdir -type d | grep -E "/Target/Source/AMiRo$" >> ${projectdir}/PowerManagement.includes
-  echo "$(realpath ${amirolldrootdir}/..)" >> ${projectdir}/PowerManagement.includes
-  find $amirolldrootdir -type d | grep -v "/doc" >> ${projectdir}/PowerManagement.includes
-  # generate a file that specifies all files
-  echo -n "" > ${projectdir}/PowerManagement.files
-  for path in `cat ${projectdir}/PowerManagement.includes`; do
-    find $path -maxdepth 1 -type f \( ! -iname ".*" \) |
-      grep -Ev "^.*((/arm-none-eabi/)|(LightRing)|(DiWheelDrive)).*$" |
-      grep -E  "^.*(\.s|\.S|\.h|\.c|\.hpp|\.cpp|\.tpp|\.ld)$" |
-      grep -Ev "^${chibiosrootdir}/os/common/ext/CMSIS/ST/STM32F4xx/((stm32f4[^0x])|(stm32f40[^5])).*$" |
-      grep -Ev "^${chibiosrootdir}/os/common/ext/CMSIS/include/((core_[^c])|(core_c[^m])|(core_cm[^4A-Za-z])|(cmsis_[^g])|(cmsis_g[^c]|(cmsis_gc[^c])))" |
-      grep -Ev "^${chibiosrootdir}/os/common/ports/ARMCMx/chcore_v[^7]m.*$" |
-      grep -Ev "^${chibiosrootdir}/os/common/ports/ARMCMx/compilers/GCC/.*_v[^7]m.*$" |
-      grep -Ev "^${chibiosrootdir}/os/common/startup/ARMCMx/compilers/GCC/.*_v[^7]m.*$" |
-      grep -Ev "^${amirobltrootdir}/Target/Source/AMiRo/helper.*$" >> ${projectdir}/PowerManagement.files;
+  # iterate over all modules
+  local retval=1
+  for module in ${modules[@]}; do
+    if [ $retval != 0 ]; then
+      printf "\n"
+    fi
+    createModuleProject modules[@] --module="$module" --path="$projectdir" --gcc="$gccincludedir"
+    retval=$?
   done
-  # generate a default project configuration file if none exists so far
-  if [ ! -f ${projectdir}/PowerManagement.config ]; then
-    echo "// Add predefined macros for your project here. For example:" > ${projectdir}/PowerManagement.config
-    echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/PowerManagement.config
-  fi
-  # generate a default .creator file if none exists so far
-  if [ ! -f ${projectdir}/PowerManagement.creator ]; then
-    echo "[general]" > ${projectdir}/PowerManagement.creator
-  fi
-
-  # go back to user directory
-  cd $userdir
-
-  # 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 ##########################################
-# Create project files for the DiWheelDrive module.
+### delete project files #######################################################
+# Deletes all project files and optionally .user files, too.
 #
-# usage:      createDiWheelDriveProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
+# usage:      deleteProjects [-p|--path=<path>] [-m|--module=<module>] [-o|--out=<var>] [-w|-wipe]
 # arguments:  -p, --path <path>
-#                 Path where to create the project files.
-#             --gcc=<path>
-#                 Path to the GCC include directory.
+#                 Path where to delete the project files.
+#             -m, --module <module>
+#                 Module name for which the project files shall be deleted.
 #             -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.
+#             -w, --wipe
+#                 Delete .user files as well.
+# return:
+#  -  0: no error
 #
-function createDiWheelDriveProject {
-  local userdir=$(pwd)
+function deleteProjects {
+  local modulename=""
   local projectdir=""
-  local gccincludedir=""
   local outvar=""
-  local gccoutvar=""
+  local wipe=false
+  local files=""
 
   # parse arguments
   local otherargs=()
@@ -756,18 +773,16 @@ function createDiWheelDriveProject {
           projectdir=$(realpath "${1#*=}"); shift 1;;
         -p|--path)
           projectdir=$(realpath "$2"); shift 2;;
-        --gcc=*)
-          gccincludedir=$(realpath "${1#*=}"); shift 1;;
-        --gcc)
-          gccincludedir=$(realpath "$2"); shift 2;;
+        -m=*|--module=*)
+          modulename="${1#*=}"; shift 1;;
+        -m|--module)
+          modulename="${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;;
+        -w|--wipe)
+          wipe=true; shift 1;;
         *)
           printError "invalid option: $1\n"; shift 1;;
       esac
@@ -777,111 +792,39 @@ function createDiWheelDriveProject {
     fi
   done
 
-  # print message
-  printInfo "creating QtCreator project files for the DiWheelDrive module...\n"
-
   # read absolute project directory if required
   if [ -z "$projectdir" ]; then
     getProjectDir projectdir
   fi
 
-  # retrieve absolute GCC include dir
-  if [ -z "$gccincludedir" ]; then
-    retrieveGccIncludeDir gccincludedir
-  fi
-
-  # move to project directory
-  cd $projectdir
-
-  # AMiRo-OS, ChibiOS, AMiRo-BLT and AMiRo-LLD relative root directories
-  local amiroosrootdir=$(realpath $(dirname ${BASH_SOURCE[0]})/../../..)
-  local chibiosrootdir=$(realpath ${amiroosrootdir}/kernel/ChibiOS)
-  local amirobltrootdir=$(realpath ${amiroosrootdir}/bootloader/AMiRo-BLT)
-  local amirolldrootdir=$(realpath ${amiroosrootdir}/periphery-lld/AMiRo-LLD)
-
-  # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories)
-  find $gccincludedir -type d > ${projectdir}/DiWheelDrive.includes
-  echo $amiroosrootdir >> ${projectdir}/DiWheelDrive.includes
-  find $amiroosrootdir/modules -type d | grep -v "/doc\|/build\|/.dep\|/LightRing\|/PowerManagement" >> ${projectdir}/DiWheelDrive.includes
-  find $amiroosrootdir/core -type d >> ${projectdir}/DiWheelDrive.includes
-  find $amiroosrootdir/unittests -type d >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/abstractions/cmsis_os$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/ext/CMSIS/(include|ST/STM32F1xx)$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/oslib/(include|src)$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/ports/ARMCMx(/compilers/GCC)?$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/common/startup/ARMCMx/(compilers/GCC|devices/STM32F1xx)$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/(include|src)$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/lib/streams" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/osal/(lib|rt)$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/hal/ports/(common/ARMCMx|STM32/(LLD/(CANv1|DACv1|DMAv1|EXTIv1|GPIOv1|I2Cv1|RTCv1|SDIOv1|SPIv1|TIMv1|USARTv1|USBv1|xWDGv1)|STM32F1xx))$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/license$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/os/rt/(include|src)$" >> ${projectdir}/DiWheelDrive.includes
-  find $chibiosrootdir -type d | grep -E "/test/(lib|rt/source/test)$" >> ${projectdir}/DiWheelDrive.includes
-  find $amirobltrootdir -type d | grep -E "/Target/Source/AMiRo$" >> ${projectdir}/DiWheelDrive.includes
-  echo "$(realpath ${amirolldrootdir}/..)" >> ${projectdir}/DiWheelDrive.includes
-  find $amirolldrootdir -type d | grep -v "/doc" >> ${projectdir}/DiWheelDrive.includes
-  # generate a file that specifies all files
-  echo -n "" > ${projectdir}/DiWheelDrive.files
-  for path in `cat ${projectdir}/DiWheelDrive.includes`; do
-    find $path -maxdepth 1 -type f \( ! -iname ".*" \) |
-      grep -Ev "^.*((/arm-none-eabi/)|(LightRing)|(PowerManagement)).*$" |
-      grep -E  "^.*(\.s|\.S|\.h|\.c|\.hpp|\.cpp|\.tpp|\.ld)$" |
-      grep -Ev "^${chibiosrootdir}/os/common/ext/CMSIS/ST/STM32F1xx/((stm32f1[^0x])|(stm32f10[^3])|(stm32f103[^x])|(stm32f103x[^e])).*$" |
-      grep -Ev "^${chibiosrootdir}/os/common/ext/CMSIS/include/((core_[^c])|(core_c[^m])|(core_cm[^3A-Za-z])|(cmsis_[^g])|(cmsis_g[^c]|(cmsis_gc[^c])))" |
-      grep -Ev "^${chibiosrootdir}/os/common/ports/ARMCMx/chcore_v[^7]m.*$" |
-      grep -Ev "^${chibiosrootdir}/os/common/ports/ARMCMx/compilers/GCC/.*_v[^7]m.*$" |
-      grep -Ev "^${chibiosrootdir}/os/common/startup/ARMCMx/compilers/GCC/.*_v[^7]m.*$" |
-      grep -Ev "^${chibiosrootdir}/os/hal/ports/STM32/STM32F1xx/.*f10[^3].*$" |
-      grep -Ev "^${amirobltrootdir}/Target/Source/AMiRo/helper.*$" >> ${projectdir}/DiWheelDrive.files;
-  done
-  # generate a default project configuration file if none exists so far
-  if [ ! -f ${projectdir}/DiWheelDrive.config ]; then
-    echo "// Add predefined macros for your project here. For example:" > ${projectdir}/DiWheelDrive.config
-    echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/DiWheelDrive.config
+  # list all files to be deleted
+  if [ -z "$modulename" ]; then
+    if [ $wipe != true ]; then
+      files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator)$")
+    else
+      files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator|creator\.user)$")
+    fi
+  else
+    if [ $wipe != true ]; then
+      files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.${modulename}\.(includes|files|config|creator)$")
+    else
+      files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.${modulename}\.(includes|files|config|creator|creator\.user)$")
+    fi
   fi
-  # generate a default .creator file if none exists so far
-  if [ ! -f ${projectdir}/DiWheelDrive.creator ]; then
-    echo "[general]" > ${projectdir}/DiWheelDrive.creator
+  if [ ! -z "$files" ]; then
+    printInfo "Deleting the following files:\n"
+    while read line; do
+      printInfo "\t$(basename ${line})\n"
+      rm ${line} 2>&1 | tee -a $LOG_FILE
+    done <<< "${files}"
+  else
+    printInfo "No project files found\n"
   fi
 
-  # go back to user directory
-  cd $userdir
-
-  # fill the output variables
+  # store the path to the output variable, if required
   if [ ! -z "$outvar" ]; then
     eval $outvar="$projectdir"
   fi
-  if [ ! -z "$gccoutvar" ]; then
-    eval $gccoutvar="$gccincludedir"
-  fi
-
-  return 0
-}
-
-### create project files for all modules #######################################
-# Create project files for all modules.
-#
-# usage:      createAllProjects
-# arguments:  n/a
-# return:     0
-#                 No error or warning occurred.
-#
-function createAllProjects {
-  # print message
-  printInfo "creating QtCreator project files for the DiWheelDrive module...\n"
-
-  # read project directory
-  local projectdir=""
-  getProjectDir projectdir
-  printInfo "files will be created in $projectdir\n"
-
-  # retrieve gcc-arm-none-eabi include dir
-  retrieveGccIncludeDir gccincludedir
-
-  # create projects
-  createLightRingProject --path="$projectdir" --gcc="$gccincludedir"
-  createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir"
-  createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir"
 
   return 0
 }
@@ -936,6 +879,22 @@ function main {
   # log script name
   printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
 
+  # detect available modules and inform user
+  local modules=()
+  detectModules modules
+  case "${#modules[@]}" in
+    0)
+      printInfo "no module has been detected\n";;
+    1)
+      printInfo "1 module has been detected:\n";;
+    *)
+      printInfo "${#modules[@]} modules have been detected:\n"
+  esac
+  for (( idx=0; idx<${#modules[@]}; ++idx )); do
+    printInfo "  - ${modules[$idx]}\n"
+  done
+  printf "\n"
+
   # parse arguments
   local otherargs=()
   while [ $# -gt 0 ]; do
@@ -943,18 +902,16 @@ function main {
       case "$1" in
         -h|--help) # already handled; ignore
           shift 1;;
+        -m=*|--module=*)
+          createModuleProject modules[@] --module="${1#*=}"; printf "\n"; shift 1;;
+        -m*|--module*)
+           createModuleProject modules[@] --module="${2}"; printf "\n"; shift 2;;
+        -a|--all)
+           createAllProjects modules[@]; 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
@@ -977,31 +934,25 @@ function main {
     # main menu info prompt and selection
     printInfo "QtCreator setup main menu\n"
     printf "Please select one of the following actions:\n"
-    printf "  [C] - clean project files\n"
-    printf "  [W] - wipe project and .user files\n"
-    printf "  [L] - create a project for the LightRing module\n"
-    printf "  [P] - create a project for the PowerManagement module\n"
-    printf "  [D] - create a project for the DiWheelDrive module\n"
+    printf "  [M] - create a project for a single module\n"
     printf "  [A] - create a project for all modules\n"
+    printf "  [C] - clean all project files\n"
+    printf "  [W] - wipe all project and .user files\n"
     printf "  [Q] - quit this setup\n"
     local userinput=""
-    readUserInput "CcWwLlPpDdAaQq" userinput
+    readUserInput "MmAaCcWwQq" userinput
     printf "\n"
 
     # evaluate user selection
     case "$userinput" in
+      M|m)
+        createModuleProject modules[@]; printf "\n";;
+      A|a)
+        createAllProjects modules[@]; printf "\n";;
       C|c)
         deleteProjects; printf "\n";;
       W|w)
         deleteProjects --wipe; printf "\n";;
-      L|l)
-        createLightRingProject; printf "\n";;
-      P|p)
-        createPowerManagementProject; printf "\n";;
-      D|d)
-        createDiWheelDriveProject; printf "\n";;
-      A|a)
-        createAllProjects; printf "\n";;
       Q|q)
         quitScript;;
       *) # sanity check (exit with error)
