Revision 2be62ace

View differences:

os/AMiRo-OS
1
Subproject commit a93a1019de6cb332cf4a1fc72451410f65077503
1
Subproject commit cacd990cefab7167a7cac1ea1f5a8ec8e87687d7
os/os.mk
33 33
# make all variables that have been set so far available to all other makefiles
34 34
export
35 35

  
36
OS_MODULES_DIR := $(realpath $(OS_DIR)/AMiRo-OS/modules)
36
OS_MODULES_DIR := $(OS_DIR)/AMiRo-OS/modules
37 37

  
tools/ide/QtCreator/QtCreatorSetup.sh
62 62
#
63 63
function printHelp {
64 64
  printInfo "printing help text\n"
65
  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [-q|--quit] [--log=<file>]\n"
65
  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [-p|--project=<project>] [-a|--all] [-c|--clean] [-w|--wipe] [-q|--quit] [--log=<file>]\n"
66 66
  printf "\n"
67 67
  printf "options:  -h, --help\n"
68 68
  printf "              Print this help text.\n"
69
  printf "          -i, --initialize\n"
70
  printf "              Initialize project files.\n"
69
  printf "          -p, --project <project>\n"
70
  printf "              Create projects for a single configuration.\n"
71
  printf "          -a, --all\n"
72
  printf "              Create projects for all configurations.\n"
71 73
  printf "          -c, --clean\n"
72 74
  printf "              Delete project files.\n"
73 75
  printf "          -w, --wipe\n"
......
81 83
### read directory where to create/delete projects #############################
82 84
# Read the directory where to create/delete project files from user.
83 85
#
84
# usage:      getProjectDir <pathvar>
86
# usage:      getProjectsDir <pathvar>
85 87
# arguments:  <pathvar>
86 88
#                 Variable to store the selected path to.
87 89
# return:     n/a
88 90
#
89
function getProjectDir {
91
function getProjectsDir {
90 92
  printLog "reading path for project files from user...\n"
91 93
  local amiroappsdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../)
92 94
  local input=""
......
105 107
#                 No error or warning occurred.
106 108
#            -1
107 109
#                 Error: Command 'arm-none-eabi-gcc' not found.
110
#            -2
111
#                 Error: include directory could not be resolved.
108 112
#
109 113
function retrieveGccIncludeDir {
110 114
  # retrieve binary path or link
111 115
  local binpath=$(which arm-none-eabi-gcc)
116
  local gccincpath=""
112 117
  if [ -z "$binpath" ]; then
113 118
    printError "command 'arm-none-eabi-gcc' not found\n"
114 119
    return -1
......
116 121

  
117 122
    # traverse any links
118 123
    while [ -L "$binpath" ]; do
119
      binpath=$(readlink $binpath)
124
      binpath=$(realpath $(dirname $binpath)/$(readlink $binpath))
120 125
    done
121 126
    printInfo "gcc-arm-none-eabi detected: $binpath\n"
122 127

  
123 128
    # return include path
124
    eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
125

  
126
    return 0
129
    gccincpath=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
130
    if [ ! -d "$gccincpath" ]; then
131
      printWarning "$gccincpath does not exist\n"
132
      return -2
133
    else
134
      eval $1="$gccincpath"
135
      return 0
136
    fi
127 137
  fi
128 138
}
129 139

  
130
### intialize project files ####################################################
131
# Initailizes all project files.
140
### detect available configurations ############################################
141
# Detect all avalable configurations.
132 142
#
133
# usage:      initProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
134
# arguments:  -p, --path <path>
143
# usage:      detectConfigurations <configurationsarray>
144
# arguments:  <configurationsarray>
145
#                 Array variable to store all detected configurations to.
146
# return:     n/a
147
#
148
function detectConfigurations {
149
  local configsdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../configurations)
150
  local configs_detected=()
151

  
152
  # detect all available modules (via directories)
153
  for dir in $(ls -d ${configsdir}/*/); do
154
    configs_detected[${#configs_detected[@]}]=$(basename $dir)
155
  done
156

  
157
  # set the output variable
158
  eval "$1=(${configs_detected[*]})"
159
}
160

  
161
### create project files for a single configuration ############################
162
# Create project files for all modules of a configuration.
163
#
164
# usage:      createConfigProjects <configurations> [-c|--config=<configuration>] [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
165
# arguments:  <configurations>
166
#                 Array containing all configurations available.
167
#             -c, --config <configuration>
168
#                 Name (folder name) of the configuration for which project files shall be generated.
169
#             -p, --path <path>
135 170
#                 Path where to create the project files.
136 171
#             --gcc=<path>
137 172
#                 Path to the GCC include directory.
......
139 174
#                 Variable to store the path to.
140 175
#             --gccout=<var>
141 176
#                 Variable to store the path to the GCC include directory to.
177
#                 If this optional arguments is absent, ths function will ask for user input.
142 178
# return:     0
143 179
#                 No error or warning occurred.
180
#             1
181
#                 Aborted by user.
182
#             2
183
#                 The selected configuration does not contain any modules.
184
#             -1
185
#                 No configurations available.
186
#             -2
187
#                 The specified <configuration> could not be found.
188
#             -3
189
#                 Parsing the project for the specified configuration failed.
190
#             -4
191
#                 Missing dependencies.
144 192
#
145
function initProject {
193
function createConfigProjects {
146 194
  local userdir=$(pwd)
147
  local projectdir=""
195
  local configsdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../configurations)
196
  local configs=("${!1}")
197
  local config=""
198
  local configidx=""
199
  local projectsdir=""
148 200
  local gccincludedir=""
149 201
  local outvar=""
150 202
  local gccoutvar=""
151 203

  
204
  # check dependencies
205
  checkCommands make
206
  if [ $? -ne 0 ]; then
207
    printError "Missing dependencies detected.\n"
208
    return -4
209
  fi
210

  
152 211
  # parse arguments
153 212
  local otherargs=()
154 213
  while [ $# -gt 0 ]; do
155 214
    if ( parseIsOption $1 ); then
156 215
      case "$1" in
216
        -c=*|--config=*)
217
          config="${1#*=}"; shift 1;;
218
        -c|--config)
219
          config="$2"; shift 2;;
157 220
        -p=*|--path=*)
158
          projectdir=$(realpath "${1#*=}"); shift 1;;
221
          projectsdir=$(realpath "${1#*=}"); shift 1;;
159 222
        -p|--path)
160
          projectdir=$(realpath "$2"); shift 2;;
223
          projectsdir=$(realpath "$2"); shift 2;;
161 224
        --gcc=*)
162 225
          gccincludedir=$(realpath "${1#*=}"); shift 1;;
163 226
        --gcc)
......
179 242
    fi
180 243
  done
181 244

  
182
  # print message
183
  printInfo "creating QtCreator project files...\n"
245
  # sanity check for the configs variable
246
  if [ -z "${configs[*]}" ]; then
247
    printError "no configurations available\n"
248
    return -1
249
  fi
250

  
251
  # select configuration
252
  if [ -z $config ]; then
253
    # list all available configurations
254
    printInfo "choose a configuration or type 'A' to abort:\n"
255
    for (( idx=0; idx<${#configs[@]}; ++idx )); do
256
      printf "%4u: %s\n" $(($idx + 1)) "${configs[$idx]}"
257
    done
258
    # read user input
259
    printLog "read user selection\n"
260
    local userinput=""
261
    while [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#configs[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; do
262
      read -p "your selection: " -e userinput
263
      printLog "user selection: $userinput\n"
264
      if [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#configs[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; then
265
        printWarning "Please enter an integer between 1 and ${#configs[@]} or 'A' to abort.\n"
266
      fi
267
    done
268
    if [[ "$userinput" =~ ^[Aa]$ ]]; then
269
      printWarning "aborted by user\n"
270
      return 1
271
    fi
272
    # store selection
273
    configidx=$(($userinput - 1))
274
    config="${configs[$configidx]}"
275
    printf "\n"
276
  else
277
    # search all configurations for the selected one
278
    for (( idx=0; idx<${#configs[@]}; ++idx )); do
279
      if [ "${configs[$idx]}" = "$config" ]; then
280
        configidx=$idx
281
        break
282
      fi
283
    done
284
    # error if the configurations could not be found
285
    if [ -z $configidx ]; then
286
      printError "configuration ($config) not available\n"
287
      return -2
288
    fi
289
  fi
290

  
291
  # retrieve modules in the configuration
292
  local modules=()
293
  if [ -d ${configsdir}/${config}/modules ]; then
294
    for dir in $(ls -d ${configsdir}/${config}/modules/*/); do
295
      modules[${#modules[@]}]=$(basename $dir)
296
    done
297
    if [ ${#modules[@]} -eq 0 ]; then
298
      printWarning "configuration ${config} does not contain any modules\n"
299
      return 2
300
    fi
301
  else
302
    printWarning "'module/' folder does not exist in configuration ${config}\n"
303
    return 2
304
  fi
184 305

  
185 306
  # read absolute project directory if required
186
  if [ -z "$projectdir" ]; then
187
    getProjectDir projectdir
307
  if [ -z "$projectsdir" ]; then
308
    getProjectsDir projectsdir
309
    printf "\n"
310
  fi
311

  
312
  # check for existing project files
313
  local projectfiles=""
314
  for module in ${modules[@]}; do
315
    projectfiles+="$(find ${projectsdir} -maxdepth 1 -type f | grep -E "${config}_${module}\.(includes|files|config|creator)$")"
316
  done
317
  IFS=$'\n'; projectfiles=($projectfiles); unset IFS
318
  if [ ! -z "${projectfiles[*]}" ]; then
319
    printWarning "The following files will be overwritten:\n"
320
    for pfile in ${projectfiles[@]}; do
321
      printWarning "\t$(basename $pfile)\n"
322
    done
323
    local userinput=""
324
    printInfo "Continue and overwrite? [y/n]\n"
325
    readUserInput "YyNn" userinput
326
    case "$userinput" in
327
      Y|y)
328
        ;;
329
      N|n)
330
        printWarning "Project generation for ${config} configuration aborted by user\n"
331
        return 1
332
        ;;
333
      *)
334
        printError "unexpected input: ${userinput}\n"; return -999;;
335
    esac
336
    printf "\n"
188 337
  fi
189 338

  
190
  # retrieve absolute GCC include dir
339
  # print message
340
  printInfo "generating QtCreator project files for the $config configuration...\n"
341

  
342
  # retrieve absolute GCC include path
191 343
  if [ -z "$gccincludedir" ]; then
192 344
    retrieveGccIncludeDir gccincludedir
193 345
  fi
194 346

  
195
  # move to project directory
196
  cd $projectdir
197

  
198
  # AMiRo-OS, ChibiOS, AMiRo-BLT, AMiRo-LLD and uRtWare relative root directories
199
  local amiroappsrootdir=$(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../..)
200
  local amiroosrootdir=$(realpath --relative-base=$projectdir ${amiroappsrootdir}/os/AMiRo-OS/os)
201
  local chibiosrootdir=$(realpath --relative-base=$projectdir ${amiroosrootdir}/../kernel/ChibiOS)
202
  local amirobltrootdir=$(realpath --relative-base=$projectdir ${amiroosrootdir}/../bootloader/AMiRo-BLT)
203
  local amirolldrootdir=$(realpath --relative-base=$projectdir ${amiroosrootdir}/../periphery-lld/AMiRo-LLD)
204
  local urtwarerootdir=$(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../middleware/uRtWare/)
205

  
206
  # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories)
207
  find $gccincludedir -type d > ${projectdir}/AMiRo-Apps.includes
208
  find $amiroappsrootdir -type d | grep -E "/(apps|configurations)/.+" >> ${projectdir}/AMiRo-Apps.includes
209
  find $amiroosrootdir -type d | grep -v "/doc\|/build\|/.dep\|/hal\|/ports" >> ${projectdir}/AMiRo-Apps.includes
210
  find $amiroosrootdir -type d | grep -E "/os/hal/(include|src)" >> ${projectdir}/AMiRo-Apps.includes
211
  find $chibiosrootdir -type d | grep -E "/os/common/abstractions/cmsis_os$" >> ${projectdir}/AMiRo-Apps.includes
212
  find $chibiosrootdir -type d | grep -E "/os/common/oslib/(include|src)$" >> ${projectdir}/AMiRo-Apps.includes
213
  find $chibiosrootdir -type d | grep -E "/os/hal/(include|src)$" >> ${projectdir}/AMiRo-Apps.includes
214
  find $chibiosrootdir -type d | grep -E "/os/hal/lib/streams" >> ${projectdir}/AMiRo-Apps.includes
215
  find $chibiosrootdir -type d | grep -E "/os/hal/osal/(lib|rt)$" >> ${projectdir}/AMiRo-Apps.includes
216
  find $chibiosrootdir -type d | grep -E "/os/license$" >> ${projectdir}/AMiRo-Apps.includes
217
  find $chibiosrootdir -type d | grep -E "/os/rt/(include|src)$" >> ${projectdir}/AMiRo-Apps.includes
218
  find $chibiosrootdir -type d | grep -E "/os/various/(shell|cpp_wrappers)" >> ${projectdir}/AMiRo-Apps.includes
219
  find $chibiosrootdir -type d | grep -E "/test/(lib|rt/source/test)$" >> ${projectdir}/AMiRo-Apps.includes
220
  find $amirobltrootdir -type d | grep -E "/Target/Source/AMiRo$" >> ${projectdir}/AMiRo-Apps.includes
221
  echo "$(realpath --relative-base=$projectdir ${amirolldrootdir}/..)" >> ${projectdir}/AMiRo-Apps.includes
222
  find $amirolldrootdir -type d | grep -v "/doc" >> ${projectdir}/AMiRo-Apps.includes
223
  find $urtwarerootdir -type d | grep -v "/doc" >> ${projectdir}/AMiRo-Apps.includes
224
  # generate a file that specifies all files
225
  echo -n "" > ${projectdir}/AMiRo-Apps.files
226
  for path in `cat ${projectdir}/AMiRo-Apps.includes`; do
227
    find $path -maxdepth 1 -type f \( ! -iname ".*" \) |
228
      grep -Ev "^.*/arm-none-eabi/.*$" |
229
      grep -E  "^.*(\.s|\.S|\.h|\.c|\.hpp|\.cpp|\.tpp|\.ld)$" |
230
      grep -Ev "^${amirobltrootdir}/Target/Source/AMiRo/helper.*$" >> ${projectdir}/AMiRo-Apps.files;
347
  # change to project directory
348
  cd "$projectsdir"
349

  
350
  # create project files for each module of the selected configuration
351
  for module in ${modules[@]}; do
352
    # run make, but only run the GCC preprocessor and produce no binaries
353
    local sourcefiles=()
354
    local sourcefile=""
355
    local parse_state="WAIT_FOR_INCLUDE_COMPILE_MAKE"
356
    local makedirs=()
357
    # capture all output from make and GCC and append the return value of make as last line
358
    printInfo "processing module ${module} (this may take a while)...\n"
359
    local rawout=$(make --directory ${configsdir}/${config}/modules/${module} --always-make USE_OPT="-v -E -H" USE_VERBOSE_COMPILE="no" OUTFILES="" 2>&1 && echo $?)
360
    # check whether the make call was successfull
361
    if [[ $(echo "${rawout}" | tail -n 1) != "0" ]]; then
362
      printError "executing 'make' in configuration directory failed\n"
363
      cd "$userdir"
364
      return -3
365
    else
366
      # cleanup
367
      make --directory ${configsdir}/${config}/modules/${module} clean &>/dev/null
368
    fi
369
    # extract file names from raw output
370
    IFS=$'\n'; rawout=($rawout); unset IFS
371
    for line in "${rawout[@]}"; do
372
      case $parse_state in
373
        WAIT_FOR_INCLUDE_COMPILE_MAKE)
374
          # lines stating include files look like:
375
          # ... <../relative/path/to/file>
376
          if [[ "$line" =~ ^\.+[[:blank:]].+\..+$ ]]; then
377
            sourcefile=${line##* }
378
            if [[ ! "$sourcefile" =~ ^/ ]]; then
379
              sourcefile=$(realpath ${makedirs[-1]}/${sourcefile})
380
            fi
381
            sourcefiles[${#sourcefiles[@]}]="$sourcefile"
382
          # whenever the next source file is processed, a message appears like:
383
          # Compiling <filename>
384
          elif [[ "$line" =~ ^Compiling[[:blank:]](.+\..+)$ ]]; then
385
            printf "."
386
            sourcefile=${BASH_REMATCH[1]}
387
            parse_state="WAIT_FOR_COMPILERCALL"
388
          # if make is called again in another directory, a message appears like:
389
          # make[1]: Entering directory 'directory'
390
          elif [[ "$line" =~ ^make(\[[0-9]+\])?:\ Entering\ directory\ \'.+\'$ ]]; then
391
            makedirs+=($(echo "$line" | (cut -d "'" -f 2)))
392
          # if make is leaving a directory, a message appears like:
393
          # make[1]: Leaving directory 'directory'
394
          elif [[ "$line" =~ ^make(\[[0-9]+\])?:\ Leaving\ directory\ \'.+\'$ ]]; then
395
            unset makedirs[-1]
396
          fi;;
397
        WAIT_FOR_COMPILERCALL)
398
          # wait for the actual call of the compiler to retrieve the full path to the source file
399
          if [[ "$line" == *${sourcefile}* ]]; then
400
            line="${line%%${sourcefile}*}${sourcefile}"
401
            line="${line##* }"
402
            if [[ "$line" =~ ^/ ]]; then
403
              # aboslute path
404
              sourcefile=$line
405
            else
406
              # relative path
407
              sourcefile=$(realpath ${makedirs[-1]}/${line##* })
408
            fi
409
            sourcefiles[${#sourcefiles[@]}]="$sourcefile"
410
            parse_state="WAIT_FOR_INCLUDE_COMPILE_MAKE"
411
          fi;;
412
      esac
413
    done
414
    unset rawout
415
    printf "\n"
416
    # sort and remove duplicates
417
    IFS=$'\n'; sourcefiles=($(sort --unique <<< "${sourcefiles[*]}")); unset IFS
418

  
419
    # extract include paths
420
    local includes=()
421
    for source in ${sourcefiles[*]}; do
422
      includes[${#includes[@]}]="$(dirname ${source})"
423
    done
424
    # sort and remove duplicates
425
    IFS=$'\n'; includes=($(sort --unique <<< "${includes[*]}")); unset IFS
426

  
427
    # generate the .incldues file, containing all include paths
428
    echo "" > ${projectsdir}/${config}_${module}.includes
429
    for inc in ${includes[*]}; do
430
      echo "$inc" >> ${projectsdir}/${config}_${module}.includes
431
    done
432
    # generate the .files file, containing all source files
433
    echo "" > ${projectsdir}/${config}_${module}.files
434
    for source in ${sourcefiles[*]}; do
435
      # skip GCC files
436
      if [[ ! "$source" =~ .*/gcc.* ]]; then
437
        echo "$source" >> ${projectsdir}/${config}_${module}.files
438
      fi
439
    done
440
    # generate a default project configuration file if it doesn't exits yet
441
    if [ ! -f ${projectsdir}/${config}_${module}.config ]; then
442
      echo "// Add predefined macros for your project here. For example:" > ${projectsdir}/${config}_${module}.config
443
      echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectsdir}/${config}_${module}.config
444
    fi
445
    # generate a default .creator file if it doesn't exist yet
446
    if [ ! -f ${projectsdir}/${config}_${module}.creator ]; then
447
      echo "[general]" > ${projectsdir}/${config}_${module}.creator
448
    fi
231 449
  done
232
  # generate a default project configuration file if none exists so far
233
  if [ ! -f ${projectdir}/AMiRo-Apps.config ]; then
234
    echo "// Add predefined macros for your project here. For example:" > ${projectdir}/AMiRo-Apps.config
235
    echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/AMiRo-Apps.config
236
  fi
237
  # generate a default .creator file if none exists so far
238
  if [ ! -f ${projectdir}/AMiRo-Apps}.creator ]; then
239
    echo "[general]" > ${projectdir}/AMiRo-Apps.creator
240
  fi
241 450

  
242 451
  # go back to user directory
243 452
  cd $userdir
244 453

  
245 454
  # fill the output variables
246 455
  if [ ! -z "$outvar" ]; then
247
    eval $outvar="$projectdir"
456
    eval $outvar="$projectsdir"
248 457
  fi
249 458
  if [ ! -z "$gccoutvar" ]; then
250 459
    eval $gccoutvar="$gccincludedir"
......
253 462
  return 0
254 463
}
255 464

  
465
### create project files for all configurations ################################
466
# Create project files for all configurations.
467
#
468
# usage:      createAllProjects <configurations> [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
469
# arguments:  <configurations>
470
#                 Array containing all configurations available.
471
#             -p, --path <path>
472
#                 Path where to create the project files.
473
#             --gcc=<path>
474
#                 Path to the GCC include directory.
475
#             -o, --out <var>
476
#                 Variable to store the path to.
477
#             --gccout=<var>
478
#                 Variable to store the path to the GCC include directory to.
479
#                 If this optional arguments is absent, ths function will ask for user input.
480
# return:     0
481
#                 No error or warning occurred.
482
#             1
483
#                 Aborted by user.
484
#             -1
485
#                 No configurations available.
486
#
487
function createAllProjects {
488
  local configs=("${!1}")
489
  local projectsdir=""
490
  local gccincludedir=""
491
  local outvar=""
492
  local gccoutvar=""
493

  
494
  # parse arguments
495
  local otherargs=()
496
  while [ $# -gt 0 ]; do
497
    if ( parseIsOption $1 ); then
498
      case "$1" in
499
        -p=*|--path=*)
500
          projectsdir=$(realpath "${1#*=}"); shift 1;;
501
        -p|--path)
502
          projectsdir=$(realpath "$2"); shift 2;;
503
        --gcc=*)
504
          gccincludedir=$(realpath "${1#*=}"); shift 1;;
505
        --gcc)
506
          gccincludedir=$(realpath "$2"); shift 2;;
507
        -o=*|--out=*)
508
          outvar=${1#*=}; shift 1;;
509
        -o|--out)
510
          outvar=$2; shift 2;;
511
        --gccout=*)
512
          gccoutvar=$(realpath "${1#*=}"); shift 1;;
513
        --gccout)
514
          gccoutvar=$(realpath "$2"); shift 2;;
515
        *)
516
          printError "invalid option: $1\n"; shift 1;;
517
      esac
518
    else
519
      otherargs+=("$1")
520
      shift 1
521
    fi
522
  done
523

  
524
  # sanity check for the configurations variable
525
  if [ -z "${configs[*]}" ]; then
526
    printError "no configurations available\n"
527
    return -1
528
  fi
529

  
530
  # read absolute project directory if required
531
  if [ -z "$projectsdir" ]; then
532
    getProjectsDir projectsdir
533
  fi
534

  
535
  # check for existing project files
536
  local projectfiles=""
537
  for config in ${configs[@]}; do
538
    for module in ${modules[@]}; do
539
      projectfiles+="$(find ${projectsdir} -maxdepth 1 -type f | grep -E "${config}_${module}\.(includes|files|config|creator)$")"
540
    done
541
  done
542
  IFS=$'\n'; projectfiles=($projectfiles); unset IFS
543
  if [ ! -z "${projectfiles[*]}" ]; then
544
    printWarning "The following files will be removed:\n"
545
    for pfile in ${projectfiles[@]}; do
546
      printWarning "\t$(basename $pfile)\n"
547
    done
548
    local userinput=""
549
    printInfo "Continue and overwrite? [y/n]\n"
550
    readUserInput "YyNn" userinput
551
    case "${userinput}" in
552
      Y|y)
553
        for pfile in ${projectfiles[*]}; do
554
          rm "$pfile"
555
        done
556
        ;;
557
      N|n)
558
        printWarning "Project generation aborted by user\n"
559
        return 1
560
        ;;
561
      *)
562
        printError "unexpected input: ${userinput}\n"
563
        return 999
564
        ;;
565
    esac
566
  fi
567

  
568
  # print message
569
  printf "\n"
570
  printInfo "generating QtCreator project files for all configurations...\n"
571

  
572
  # retrieve absolute GCC include path
573
  if [ -z "$gccincludedir" ]; then
574
    retrieveGccIncludeDir gccincludedir
575
  fi
576

  
577
  # iterate over all configurations
578
  local retval=1
579
  for config in ${configs[@]}; do
580
    if [ $retval != 0 ]; then
581
      printf "\n"
582
    fi
583
    createConfigProjects configs[@] --config="$config" --path="$projectsdir" --gcc="$gccincludedir"
584
    retval=$?
585
  done
586

  
587
  return 0
588
}
589

  
256 590
### delete project files #######################################################
257 591
# Deletes all project files and optionally .user files, too.
258 592
#
259
# usage:      deleteProject [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe]
593
# usage:      deleteProjects [-p|--path=<path>] [-c|--config=<configuration>] [-o|--out=<var>] [-w|-wipe]
260 594
# arguments:  -p, --path <path>
261 595
#                 Path where to delete the project files.
596
#             -c, --config <configuration>
597
#                 Configuration name for which the project files shall be deleted.
262 598
#             -o, --out <var>
263 599
#                 Variable to store the path to.
264 600
#             -w, --wipe
265 601
#                 Delete .user files as well.
266 602
# return:
267 603
#  -  0: no error
268
#  -  1: warning: function aborted by user
269
#  - -1: error: unexpected user input
270
function deleteProject {
271
  local projectdir=""
604
#
605
function deleteProjects {
606
  local config=""
607
  local projectsdir=""
272 608
  local outvar=""
273 609
  local wipe=false
610
  local files=""
274 611

  
275 612
  # parse arguments
276 613
  local otherargs=()
......
278 615
    if ( parseIsOption $1 ); then
279 616
      case "$1" in
280 617
        -p=*|--path=*)
281
          projectdir=$(realpath "${1#*=}"); shift 1;;
618
          projectsdir=$(realpath "${1#*=}"); shift 1;;
282 619
        -p|--path)
283
          projectdir=$(realpath "$2"); shift 2;;
620
          projectsdir=$(realpath "$2"); shift 2;;
621
        -c=*|--config=*)
622
          config="${1#*=}"; shift 1;;
623
        -c|--config)
624
          config="${2}"; shift 2;;
284 625
        -o=*|--out=*)
285 626
          outvar=${1#*=}; shift 1;;
286 627
        -o|--out)
......
296 637
    fi
297 638
  done
298 639

  
299
  # print message
300
  if [ $wipe != true ]; then
301
    printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n"
302
  else
303
    printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n"
640
  # read absolute project directory if required
641
  if [ -z "$projectsdir" ]; then
642
    getProjectsDir projectsdir
304 643
  fi
305 644

  
306
  # read project directory if required
307
  if [ -z "$projectdir" ]; then
308
    getProjectDir projectdir
645
  # list all files to be deleted
646
  if [ -z "$config" ]; then
647
    if [ $wipe != true ]; then
648
      files=$(find "${projectsdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator|cflags|cxxflags)$")
649
    else
650
      files=$(find "${projectsdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator|cflags|cxxflags|creator(\.user(\..+)?)?)$")
651
    fi
652
  else
653
    if [ $wipe != true ]; then
654
      files=$(find "${projectsdir}" -maxdepth 1 -type f | grep -E "^${config}_.+\.(includes|files|config|creator|cflags|cxxflags)$")
655
    else
656
      files=$(find "${projectsdir}" -maxdepth 1 -type f | grep -E "^${config}_.+\.(includes|files|config|creator|cflags|cxxflags|creator(\.user(\..+)?)?)$")
657
    fi
309 658
  fi
310

  
311
  # remove all project files
312
  rm ${projectdir}/AMiRo-Apps.includes 2>&1 | tee -a $LOG_FILE
313
  rm ${projectdir}/AMiRo-Apps.files 2>&1 | tee -a $LOG_FILE
314
  rm ${projectdir}/AMiRo-Apps.config 2>&1 | tee -a $LOG_FILE
315
  rm ${projectdir}/AMiRo-Apps.creator 2>&1 | tee -a $LOG_FILE
316

  
317
  if [ $wipe == true ]; then
318
    rm ${projectdir}/AMiRo-Apps.creator.user 2>&1 | tee -a $LOG_FILE
659
  if [ ! -z "$files" ]; then
660
    printInfo "Deleting the following files:\n"
661
    while read line; do
662
      printInfo "\t$(basename ${line})\n"
663
      rm ${line} 2>&1 | tee -a $LOG_FILE
664
    done <<< "${files}"
665
  else
666
    printInfo "No project files found\n"
319 667
  fi
320 668

  
321 669
  # store the path to the output variable, if required
322 670
  if [ ! -z "$outvar" ]; then
323
    eval $outvar="$projectdir"
671
    eval $outvar="$projectsdir"
324 672
  fi
325 673

  
326 674
  return 0
327

  
328 675
}
329 676

  
330 677
### main function of this script ###############################################
331
# Creates, deletes and wipes QtCreator project files for the three AMiRo base modules.
678
# Creates, deletes and wipes QtCreator project files.
332 679
#
333 680
# usage:      see function printHelp
334 681
# arguments:  see function printHelp
......
377 724
  # log script name
378 725
  printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
379 726

  
727
  # detect available configurations and inform user
728
  local configurations=()
729
  detectConfigurations configurations
730
  case "${#configurations[@]}" in
731
    0)
732
      printInfo "no configuration has been detected\n";;
733
    1)
734
      printInfo "1 configuration has been detected:\n";;
735
    *)
736
      printInfo "${#configurations[@]} configurations have been detected:\n";;
737
  esac
738
  for (( idx=0; idx<${#configurations[@]}; ++idx )); do
739
    printInfo "  - ${configurations[$idx]}\n"
740
  done
741
  printf "\n"
742

  
380 743
  # parse arguments
381 744
  local otherargs=()
382 745
  while [ $# -gt 0 ]; do
......
384 747
      case "$1" in
385 748
        -h|--help) # already handled; ignore
386 749
          shift 1;;
750
        -p=*|--project=*)
751
          createConfigProjects configurations[@] --configuration="${1#*=}"; printf "\n"; shift 1;;
752
        -p|--project)
753
          createConfigProjects configurations[@] --configuration="${2}"; printf "\n"; shift 2;;
754
        -a|--all)
755
          createAllProjects configurations[@]; shift 1;;
387 756
        -c|--clean)
388 757
          deleteProjects; printf "\n"; shift 1;;
389 758
        -w|--wipe)
......
410 779
    # main menu info prompt and selection
411 780
    printInfo "QtCreator setup main menu\n"
412 781
    printf "Please select one of the following actions:\n"
413
    printf "  [I] - initialize project files\n"
782
    printf "  [P] - create projects for a single configuration\n"
783
    printf "  [A] - create projects for all configurations\n"
414 784
    printf "  [C] - clean project files\n"
415 785
    printf "  [W] - wipe project and .user files\n"
416 786
    printf "  [Q] - quit this setup\n"
417 787
    local userinput=""
418
    readUserInput "IiCcWwQq" userinput
788
    readUserInput "PpAaCcWwQq" userinput
419 789
    printf "\n"
420 790

  
421 791
    # evaluate user selection
422 792
    case "$userinput" in
423
      I|i)
424
        initProject; printf "\n";;
793
      P|p)
794
        createConfigProjects configurations[@]; printf "\n";;
795
      A|a)
796
        createAllProjects configurations[@]; printf "\n";;
425 797
      C|c)
426
        deleteProject; printf "\n";;
798
        deleteProjects; printf "\n";;
427 799
      W|w)
428
        deleteProject --wipe; printf "\n";;
800
        deleteProjects --wipe; printf "\n";;
429 801
      Q|q)
430 802
        quitScript;;
431 803
      *) # sanity check (exit with error)
......
441 813
################################################################################
442 814

  
443 815
main "$@"
816

  

Also available in: Unified diff