Revision 7387fb42

View differences:

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] [-p|--project=<module>] [-d|--delete=<module>] [-q|--quit] [--log=<file>]\n"
65
  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--create=<module>] [-d|--delete=<module>] [-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 "          -p, --project <module>\n"
69
  printf "          -c, --create <module>\n"
70 70
  printf "              Create project files for a sigle module or for all modules (<module>='*').\n"
71 71
  printf "          -d, --delete <module>\n"
72
  printf "              Delete projet files of a single module or of all modules (<module>='*')."
72
  printf "              Delete projet files of a single module or of all modules (<module>='*').\n"
73 73
  printf "          -q, --quit\n"
74 74
  printf "              Quit the script.\n"
75 75
  printf "          --log=<file>\n"
......
108 108
#                 Error: include directory could not be resolved.
109 109
#
110 110
function retrieveGccIncludeDir {
111
  # retrieve binary path or link
112 111
  local binpath=$(which arm-none-eabi-gcc)
113 112
  local gccincpath=""
113

  
114
  # retrieve binary path or link
114 115
  if [ -z "$binpath" ]; then
115 116
    printError "command 'arm-none-eabi-gcc' not found\n"
116 117
    return -1
......
143 144
# return:     n/a
144 145
#
145 146
function detectModules {
146
  local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../modules)
147 147
  local modules_detected=()
148
  local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../modules)
148 149

  
149 150
  # detect all available modules (via directories)
150 151
  for dir in $(ls -d ${modulesdir}/*/); do
......
186 187
#                 Missing dependencies.
187 188
#
188 189
function createProject {
189
  local userdir=$(pwd)
190
  local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../modules)
191
  local modules=("${!1}")
192
  local module=""
193
  local projectdir=""
194 190
  local gccincludedir=""
195
  local outvar=""
196 191
  local gccoutvar=""
192
  local includes=()
193
  local makedir=""
194
  local makedirs=()
195
  local module=""
196
  local modules=("${!1}")
197 197
  local modules2generate=()
198
  local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../modules)
199
  local otherargs=()
200
  local outvar=""
201
  local parse_state=""
202
  local projectdir=""
203
  local projectfiles=()
204
  local quotes="\'\"\´\`\„\“"
205
  local rawout=""
206
  local sourcefile=""
207
  local sourcefiles=()
208
  local userdir=$(pwd)
209
  local userinput=""
198 210

  
199 211
  # check dependencies
200 212
  checkCommands make
......
204 216
  fi
205 217

  
206 218
  # parse arguments
207
  local otherargs=()
208 219
  while [ $# -gt 0 ]; do
209 220
    if ( parseIsOption $1 ); then
210 221
      case "$1" in
......
252 263
    done
253 264
    # read user input
254 265
    printLog "read user selection\n"
255
    local userinput=""
266
    userinput=""
256 267
    while [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#modules[@]} ] && [[ ! "$userinput" =~ ^(\*|[Aa])$ ]]; do
257 268
      read -p "your selection: " -e userinput
258 269
      printLog "user selection: $userinput\n"
......
287 298
  fi
288 299

  
289 300
  # check for existing project files
290
  local projectfiles=()
291 301
  for module in ${modules2generate[@]}; do
292 302
    projectfiles+=($(find ${projectdir} -maxdepth 1 -type f -regextype posix-extended -regex "^.*/${module}\.(includes|files|config|creator)$" | sort))
293 303
  done
......
296 306
    for pfile in ${projectfiles[@]}; do
297 307
      printWarning "\t$(basename $pfile)\n"
298 308
    done
299
    local userinput=""
309
    userinput=""
300 310
    printInfo "Continue and overwrite? [y/n]\n"
301 311
    readUserInput "YyNn" userinput
302 312
    case "$userinput" in
......
318 328
  fi
319 329

  
320 330
  # generate all modules
331
  cd "$projectdir"
321 332
  for module in ${modules2generate[@]}; do
322 333
    # print message
323 334
    printInfo "generating QtCreator project files for the $module module...\n"
324 335

  
325
    # change to project directory
326
    cd "$projectdir"
327

  
328 336
    # run make, but only run the GCC preprocessor and produce no binaries
329
    local sourcefiles=()
330
    local sourcefile=""
331
    local parse_state="WAIT_FOR_INCLUDE_COMPILE_MAKE"
332
    local makedir=""
333
    local makedirs=()
334
    local quotes="\'\"\´\`\„\“"
337
    sourcefiles=()
338
    sourcefile=""
339
    parse_state="WAIT_FOR_INCLUDE_COMPILE_MAKE"
340
    makedir=""
341
    makedirs=()
335 342
    # capture all output from make and GCC and append the return value of make as last line
336 343
    printInfo "processing project (this may take a while)...\n"
337
    local rawout=$(make --directory ${modulesdir}/${module} --always-make USE_OPT="-v -E -H" USE_VERBOSE_COMPILE="no" OUTFILES="" 2>&1 && echo $?)
344
    rawout=$(make --directory ${modulesdir}/${module} --always-make USE_OPT="-v -E -H" USE_VERBOSE_COMPILE="no" OUTFILES="" 2>&1 && echo $?)
338 345
    # check whether the make call was successfull
339 346
    if [[ $(echo "${rawout}" | tail -n 1) != "0" ]]; then
340 347
      printError "executing 'make' in module directory failed\n"
......
395 402
          fi;;
396 403
      esac
397 404
    done
398
    unset rawout
399 405
    printf "\n"
400 406
    # sort and remove duplicates
401 407
    IFS=$'\n'; sourcefiles=($(sort --unique <<< "${sourcefiles[*]}")); unset IFS
402 408

  
403 409
    # extract include paths
404
    local includes=()
410
    includes=()
405 411
    for source in ${sourcefiles[*]}; do
406 412
      includes[${#includes[@]}]="$(dirname ${source})"
407 413
    done
......
430 436
    if [ ! -f ${projectdir}/${module}.creator ]; then
431 437
      echo "[general]" > ${projectdir}/${module}.creator
432 438
    fi
433

  
434
    # go back to user directory
435
    cd $userdir
436 439
  done
437 440

  
441
  # go back to user directory
442
  cd "$userdir"
443

  
438 444
  # fill the output variables
439 445
  if [ ! -z "$outvar" ]; then
440 446
    eval $outvar="$projectdir"
......
453 459
# arguments:  -p, --path <path>
454 460
#                 Path where to delete the project files.
455 461
#             -m, --module <module>
456
#                 Module name for which the project files shall be deleted or '*' delete for all projects.
462
#                 Module name for which the project files shall be deleted or '*' to delete for all modules.
457 463
#             -o, --out <var>
458 464
#                 Variable to store the path to.
459 465
#             -w, --wipe <flag>
......
463 469
#             1
464 470
#               Aborted by user.
465 471
#             2
466
#               There is no project files (for the specified module) at the specified location.
472
#               There are no project files (for the specified module) at the specified location.
467 473
#
468 474
function deleteProject {
475
  local files=()
469 476
  local module=""
470 477
  local modules=()
471
  local projectdir=""
472
  local outvar=""
473
  local wipe=""
474 478
  local modules2delete=()
475
  local files=()
479
  local otherargs=()
480
  local outvar=""
481
  local projectdir=""
476 482
  local userinput=""
483
  local wipe=""
477 484

  
478 485
  # parse arguments
479
  local otherargs=()
480 486
  while [ $# -gt 0 ]; do
481 487
    if ( parseIsOption $1 ); then
482 488
      case "$1" in
......
506 512
  done
507 513

  
508 514
  # sanity checks on parameters
509
  if [ ! -z $wipe ] && [[ ! "$wipe" =~ "(true|false)" ]]; then
515
  if [ ! -z $wipe ] && [[ ! "$wipe" =~ ^(true|false)$ ]]; then
510 516
    printWarning "invalid value set to 'wipe' argument\n"
511
    printInfo "I will act as if there was no --wipe argument and ask for input later.\n"
517
    printInfo "I will act as if there was no '--wipe' argument and ask for input later.\n"
512 518
    wipe=""
513 519
  fi
514 520

  
......
519 525
  fi
520 526

  
521 527
  # retrieve all modules in the specified directory
522
  modules=($(find "${projectdir}" -maxdepth 1 -type f -regextype posix-extended -regex "^.+\.(includes|files|config|creator|cflags|cxxflags|creator(\.user(\..+)?)?)$" | grep -oE "/[^/\.]+\." | grep -oE "[^/].+[^\.]" | sort --unique))
528
  modules=($(find "${projectdir}" -maxdepth 1 -type f -regextype posix-extended -regex "^.+\.(includes|files|config|creator|cflags|cxxflags|creator\.user(\..+)?)$" | grep -oE "/[^/\.]+\." | grep -oE "[^/].+[^\.]" | sort --unique))
523 529

  
524 530
  # check whether there are any project files at the specified location
525 531
  if [ ${#modules[@]} -eq 0 ]; then
......
552 558
    elif [[ "$userinput" =~ ^[Aa]$ ]]; then
553 559
      printWarning "aborted by user\n"
554 560
      return 1
561
    else
562
      printError "unexpected user input: ${userinput}\n"
563
      return -999
555 564
    fi
556 565
    printf "\n"
557 566
  else
......
564 573
    fi
565 574
  fi
566 575

  
567
  # retrieve all files
576
  # check for .user files
577
  files=()
568 578
  for module in ${modules2delete[@]}; do
569
    files+=($(find "${projectdir}" -maxdepth 1 -type f -regextype posix-extended -regex "^.*${module}\.(includes|files|config|creator|cflags|cxxflags|creator\.user(\..+)?)$"))
579
    files+=($(find "${projectdir}" -maxdepth 1 -type f -regextype posix-extended -regex "^.*${module}\.creator\.user(\..+)?)$"))
570 580
  done
571 581

  
572 582
  # read wipe information if required
573
  if [[ "${files[@]}" =~ ^.+\.creator\.user(\..+)?$ ]] &&  [ -z "$wipe" ]; then
583
  if [ ${#files[@]} -gt 0 ] &&  [ -z "$wipe" ]; then
574 584
    userinput=""
575 585
    printInfo "Wipe user data as well? [y/n]\n"
576 586
    readUserInput "YyNn" userinput
......
585 595
    printf "\n"
586 596
  fi
587 597

  
588
  # remove .user files if required
589
  if [ ! "$wipe" = "true" ]; then
590
    files=()
591
    for module in ${modules2delete[@]}; do
598
  # retrieve all files
599
  files=()
600
  for module in ${modules2delete[@]}; do
601
    if [ "$wipe" == "true" ]; then
602
      files+=($(find "${projectdir}" -maxdepth 1 -type f -regextype posix-extended -regex "^.*${module}\.(includes|files|config|creator|cflags|cxxflags|creator\.user(\..+)?)$"))
603
    else
592 604
      files+=($(find "${projectdir}" -maxdepth 1 -type f -regextype posix-extended -regex "^.*${module}\.(includes|files|config|creator|cflags|cxxflags)$"))
593
    done
594
  fi
605
    fi
606
  done
595 607

  
596 608
  # list all files to be deleted and ask for confirmation
597 609
  if [ ${#files[@]} -gt 0 ]; then
598
    printInfo "The following files will be deleted:\n"
610
    printWarning "The following files will be deleted:\n"
599 611
    for file in ${files[@]}; do
600
      printInfo "\t$(basename ${file})\n"
612
      printWarning "\t$(basename ${file})\n"
601 613
    done
602 614
    userinput=""
603 615
    printInfo "Do you want to continue? [y/n]\n"
......
612 624
        printError "unexpected input: ${userinput}\n"; return -999;;
613 625
    esac
614 626
  else
615
    printInfo "No files to delete.\n"
627
    printInfo "no files to delete\n"
616 628
  fi
617 629

  
618 630
  # finally delete the files
......
637 649
#                 No error or warning ocurred.
638 650
#
639 651
function main {
640
# print welcome/info text if not suppressed
652
  local cmd=""
653
  local cmdidx=""
654
  local filenameidx=""
655
  local logfile=""
656
  local modules=()
657
  local otherargs=()
658
  local userinput=""
659

  
660
  # print welcome/info text if not suppressed
641 661
  if [[ $@ != *"--noinfo"* ]]; then
642 662
    printWelcomeText
643 663
  else
......
655 675
  # set log file if specified
656 676
  if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then
657 677
    # get the parameter (file name)
658
    local cmdidx=1
678
    cmdidx=1
659 679
    while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do
660 680
      cmdidx=$[cmdidx + 1]
661 681
    done
662
    local cmd="${!cmdidx}"
663
    local logfile=""
682
    cmd="${!cmdidx}"
683
    logfile=""
664 684
    if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then
665 685
      logfile=${cmd#*=}
666 686
    else
667
      local filenameidx=$((cmdidx + 1))
687
      filenameidx=$((cmdidx + 1))
668 688
      logfile="${!filenameidx}"
669 689
    fi
670 690
    # optionally force silent appending
......
679 699
  printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
680 700

  
681 701
  # detect available modules and inform user
682
  local modules=()
683 702
  detectModules modules
684 703
  case "${#modules[@]}" in
685 704
    0)
......
695 714
  printf "\n"
696 715

  
697 716
  # parse arguments
698
  local otherargs=()
699 717
  while [ $# -gt 0 ]; do
700 718
    if ( parseIsOption $1 ); then
701 719
      case "$1" in
702 720
        -h|--help) # already handled; ignore
703 721
          shift 1;;
704
        -p=*|--project=*)
722
        -c=*|--create=*)
705 723
          createProject modules[@] --module="${1#*=}"; printf "\n"; shift 1;;
706
        -p|--project)
724
        -c|--create)
707 725
          createProject modules[@] --module="${2}"; printf "\n"; shift 2;;
708 726
        -d=*|--delete=*)
709 727
          deleteProject --module="${1#*=}"; printf "\n"; shift 1;;
......
731 749
    # main menu info prompt and selection
732 750
    printInfo "QtCreator setup main menu\n"
733 751
    printf "Please select one of the following actions:\n"
734
    printf "  [P] - create project files\n"
752
    printf "  [C] - create project files\n"
735 753
    printf "  [D] - delete project files\n"
736 754
    printf "  [Q] - quit this setup\n"
737
    local userinput=""
738
    readUserInput "PpDdQq" userinput
755
    userinput=""
756
    readUserInput "CcDdQq" userinput
739 757
    printf "\n"
740 758

  
741 759
    # evaluate user selection
742 760
    case "$userinput" in
743
      P|p)
761
      C|c)
744 762
        createProject modules[@]; printf "\n";;
745 763
      D|d)
746 764
        deleteProject; printf "\n";;

Also available in: Unified diff