Revision 6c75ad52
tools/ide/QtCreator/QtCreatorSetup.sh | ||
---|---|---|
337 | 337 |
# |
338 | 338 |
function printHelp { |
339 | 339 |
printInfo "printing help text\n" |
340 |
printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [--LightRing] [--PowerManagement] [--DiWheelDrive] [-a|--all] [-q|--quit] [--log=<file>]\n"
|
|
340 |
printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [--module=<module>] [-a|--all] [-c|--clean] [-w|--wipe] [-q|--quit] [--log=<file>]\n"
|
|
341 | 341 |
printf "\n" |
342 | 342 |
printf "options: -h, --help\n" |
343 | 343 |
printf " Print this help text.\n" |
344 |
printf " --module=<module>\n" |
|
345 |
printf " Create project for a single module.\n" |
|
346 |
printf " -a, --all\n" |
|
347 |
printf " Create projects for all modules.\n" |
|
344 | 348 |
printf " -c, --clean\n" |
345 | 349 |
printf " Delete project files.\n" |
346 | 350 |
printf " -w, --wipe\n" |
347 | 351 |
printf " Delete project and .user files.\n" |
348 |
printf " --LightRing\n" |
|
349 |
printf " Create project for the LightRing module.\n" |
|
350 |
printf " --PowerManagement\n" |
|
351 |
printf " Create project for the PowerManagement module.\n" |
|
352 |
printf " --DiWheelDrive\n" |
|
353 |
printf " Create project for the DiWheelDrive module.\n" |
|
354 |
printf " -a, --all\n" |
|
355 |
printf " Create projects for all modules.\n" |
|
356 | 352 |
printf " -q, --quit\n" |
357 | 353 |
printf " Quit the script.\n" |
358 | 354 |
printf " --log=<file>\n" |
... | ... | |
386 | 382 |
# No error or warning occurred. |
387 | 383 |
# -1 |
388 | 384 |
# Error: Command 'arm-none-eabi-gcc' not found. |
385 |
# -2 |
|
386 |
# Error: include directory could not be resolved |
|
389 | 387 |
# |
390 | 388 |
function retrieveGccIncludeDir { |
391 | 389 |
# retrieve binary path or link |
392 | 390 |
local binpath=$(which arm-none-eabi-gcc) |
391 |
local gccincpath="" |
|
393 | 392 |
if [ -z "$binpath" ]; then |
394 | 393 |
printError "command 'arm-none-eabi-gcc' not found\n" |
395 | 394 |
return -1 |
... | ... | |
402 | 401 |
printInfo "gcc-arm-none-eabi detected: $binpath\n" |
403 | 402 |
|
404 | 403 |
# return include path |
405 |
eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/) |
|
406 |
|
|
407 |
return 0 |
|
404 |
gccincpath=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/) |
|
405 |
if [ ! -d "$gccincpath" ]; then |
|
406 |
printWarning "$gccincpath does not exist\n" |
|
407 |
return -2 |
|
408 |
else |
|
409 |
eval $1="$gccincpath" |
|
410 |
return 0 |
|
411 |
fi |
|
408 | 412 |
fi |
409 | 413 |
} |
410 | 414 |
|
411 |
### delete project files #######################################################
|
|
412 |
# Deletes all project files and optionally .user files, too.
|
|
415 |
### detect available modules ###################################################
|
|
416 |
# Detect all avalable modules supported by AMiRo-OS.
|
|
413 | 417 |
# |
414 |
# usage: deleteProjects [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe] |
|
415 |
# arguments: -p, --path <path> |
|
416 |
# Path where to delete the project files. |
|
417 |
# -o, --out <var> |
|
418 |
# Variable to store the path to. |
|
419 |
# -w, --wipe |
|
420 |
# Delete .user files as well. |
|
421 |
# return: |
|
422 |
# - 0: no error |
|
423 |
# - 1: warning: function aborted by user |
|
424 |
# - -1: error: unexpected user input |
|
425 |
function deleteProjects { |
|
426 |
local projectdir="" |
|
427 |
local outvar="" |
|
428 |
local wipe=false |
|
418 |
# usage: detectModules <modulearray> |
|
419 |
# arguments: <modulearray> |
|
420 |
# Array variable to store all detected modules to. |
|
421 |
# return: n/a |
|
422 |
# |
|
423 |
function detectModules { |
|
424 |
local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/Modules) |
|
425 |
local modules_detected=() |
|
429 | 426 |
|
430 |
# parse arguments |
|
431 |
local otherargs=() |
|
432 |
while [ $# -gt 0 ]; do |
|
433 |
if ( parseIsOption $1 ); then |
|
434 |
case "$1" in |
|
435 |
-p=*|--path=*) |
|
436 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
|
437 |
-p|--path) |
|
438 |
projectdir=$(realpath "$2"); shift 2;; |
|
439 |
-o=*|--out=*) |
|
440 |
outvar=${1#*=}; shift 1;; |
|
441 |
-o|--out) |
|
442 |
outvar=$2; shift 2;; |
|
443 |
-w|--wipe) |
|
444 |
wipe=true; shift 1;; |
|
445 |
*) |
|
446 |
printError "invalid option: $1\n"; shift 1;; |
|
447 |
esac |
|
448 |
else |
|
449 |
otherargs+=("$1") |
|
450 |
shift 1 |
|
451 |
fi |
|
427 |
# detect all available modules (via directories) |
|
428 |
for dir in $(ls -d ${modulesdir}/*/); do |
|
429 |
modules_detected[${#modules_detected[@]}]=$(basename $dir) |
|
452 | 430 |
done |
453 | 431 |
|
454 |
# print message |
|
455 |
if [ $wipe != true ]; then |
|
456 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n" |
|
457 |
else |
|
458 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n" |
|
459 |
fi |
|
460 |
|
|
461 |
# read project directory if required |
|
462 |
if [ -z "$projectdir" ]; then |
|
463 |
getProjectDir projectdir |
|
464 |
fi |
|
465 |
|
|
466 |
# remove all project files |
|
467 |
rm ${projectdir}/LightRing.includes 2>&1 | tee -a $LOG_FILE |
|
468 |
rm ${projectdir}/PowerManagement.includes 2>&1 | tee -a $LOG_FILE |
|
469 |
rm ${projectdir}/DiWheelDrive.includes 2>&1 | tee -a $LOG_FILE |
|
470 |
|
|
471 |
rm ${projectdir}/LightRing.files 2>&1 | tee -a $LOG_FILE |
|
472 |
rm ${projectdir}/PowerManagement.files 2>&1 | tee -a $LOG_FILE |
|
473 |
rm ${projectdir}/DiWheelDrive.files 2>&1 | tee -a $LOG_FILE |
|
474 |
|
|
475 |
rm ${projectdir}/LightRing.config 2>&1 | tee -a $LOG_FILE |
|
476 |
rm ${projectdir}/PowerManagement.config 2>&1 | tee -a $LOG_FILE |
|
477 |
rm ${projectdir}/DiWheelDrive.config 2>&1 | tee -a $LOG_FILE |
|
478 |
|
|
479 |
rm ${projectdir}/LightRing.creator 2>&1 | tee -a $LOG_FILE |
|
480 |
rm ${projectdir}/PowerManagement.creator 2>&1 | tee -a $LOG_FILE |
|
481 |
rm ${projectdir}/DiWheelDrive.creator 2>&1 | tee -a $LOG_FILE |
|
482 |
|
|
483 |
if [ $wipe == true ]; then |
|
484 |
rm ${projectdir}/LightRing.creator.user 2>&1 | tee -a $LOG_FILE |
|
485 |
rm ${projectdir}/PowerManagement.creator.user 2>&1 | tee -a $LOG_FILE |
|
486 |
rm ${projectdir}/DiWheelDrive.creator.user 2>&1 | tee -a $LOG_FILE |
|
487 |
fi |
|
488 |
|
|
489 |
# store the path to the output variable, if required |
|
490 |
if [ ! -z "$outvar" ]; then |
|
491 |
eval $outvar="$projectdir" |
|
492 |
fi |
|
493 |
|
|
494 |
return 0 |
|
432 |
# set the output variable |
|
433 |
eval "$1=(${modules_detected[*]})" |
|
495 | 434 |
} |
496 | 435 |
|
497 |
### create LightRing project files #############################################
|
|
498 |
# Create project files for the LightRing module.
|
|
436 |
### create project files for a single module ###################################
|
|
437 |
# Create project files for a single module.
|
|
499 | 438 |
# |
500 |
# usage: createLightRingProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
|
501 |
# arguments: -p, --path <path> |
|
439 |
# usage: createModuleProject <modules> [-m|--module=<module>] [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
|
440 |
# arguments: <modules> |
|
441 |
# Array containing all modules available. |
|
442 |
# -m, --module <module> |
|
443 |
# Name (folder name) of the module for which project files shall be generated. |
|
444 |
# -p, --path <path> |
|
502 | 445 |
# Path where to create the project files. |
503 | 446 |
# --gcc=<path> |
504 | 447 |
# Path to the GCC include directory. |
... | ... | |
506 | 449 |
# Variable to store the path to. |
507 | 450 |
# --gccout=<var> |
508 | 451 |
# Variable to store the path to the GCC include directory to. |
452 |
# If this optional arguments is absent, ths function will ask for user input. |
|
509 | 453 |
# return: 0 |
510 | 454 |
# No error or warning occurred. |
455 |
# 1 |
|
456 |
# Aborted by user. |
|
457 |
# -1 |
|
458 |
# No modules available. |
|
459 |
# -2 |
|
460 |
# The specified <module> could not be found. |
|
461 |
# -3 |
|
462 |
# Parsing the project for the specified module failed. |
|
463 |
# -4 |
|
464 |
# Missing dependencies. |
|
511 | 465 |
# |
512 |
function createLightRingProject {
|
|
466 |
function createModuleProject {
|
|
513 | 467 |
local userdir=$(pwd) |
468 |
local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/Modules) |
|
469 |
local modules=("${!1}") |
|
470 |
local module="" |
|
471 |
local moduleidx="" |
|
514 | 472 |
local projectdir="" |
515 | 473 |
local gccincludedir="" |
516 | 474 |
local outvar="" |
517 | 475 |
local gccoutvar="" |
518 | 476 |
|
477 |
# check dependencies |
|
478 |
checkCommands make |
|
479 |
if [ $? -ne 0 ]; then |
|
480 |
printError "Missing dependencies detected.\n" |
|
481 |
return -4 |
|
482 |
fi |
|
483 |
|
|
519 | 484 |
# parse arguments |
520 | 485 |
local otherargs=() |
521 | 486 |
while [ $# -gt 0 ]; do |
522 | 487 |
if ( parseIsOption $1 ); then |
523 | 488 |
case "$1" in |
489 |
-m=*|--module=*) |
|
490 |
module="${1#*=}"; shift 1;; |
|
491 |
-m|--module) |
|
492 |
module="$2"; shift 2;; |
|
524 | 493 |
-p=*|--path=*) |
525 | 494 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
526 | 495 |
-p|--path) |
... | ... | |
546 | 515 |
fi |
547 | 516 |
done |
548 | 517 |
|
549 |
# print message |
|
550 |
printInfo "creating QtCreator project files for the LightRing module...\n" |
|
518 |
# sanity check for the modules variable |
|
519 |
if [ -z "${modules[*]}" ]; then |
|
520 |
printError "no modules available\n" |
|
521 |
return -1 |
|
522 |
fi |
|
523 |
|
|
524 |
# select module |
|
525 |
if [ -z $module ]; then |
|
526 |
# list all available modules |
|
527 |
printInfo "choose a module or type 'A' to abort:\n" |
|
528 |
for (( idx=0; idx<${#modules[@]}; ++idx )); do |
|
529 |
printf "%4u: %s\n" $(($idx + 1)) "${modules[$idx]}" |
|
530 |
done |
|
531 |
# read user input |
|
532 |
printLog "read user selection\n" |
|
533 |
local userinput="" |
|
534 |
while [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#modules[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; do |
|
535 |
read -p "your selection: " -e userinput |
|
536 |
printLog "user selection: $userinput\n" |
|
537 |
if [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#modules[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; then |
|
538 |
printWarning "Please enter an integer between 1 and ${#modules[@]} or 'A' to abort.\n" |
|
539 |
fi |
|
540 |
done |
|
541 |
if [[ "$userinput" =~ ^[Aa]$ ]]; then |
|
542 |
printWarning "aborted by user\n" |
|
543 |
return 1 |
|
544 |
fi |
|
545 |
# store selection |
|
546 |
moduleidx=$(($userinput - 1)) |
|
547 |
module="${modules[$moduleidx]}" |
|
548 |
printf "\n" |
|
549 |
else |
|
550 |
# search all modules for the selected one |
|
551 |
for (( idx=0; idx<${#modules[@]}; ++idx )); do |
|
552 |
if [ "${modules[$idx]}" = "$module" ]; then |
|
553 |
moduleidx=$idx |
|
554 |
break |
|
555 |
fi |
|
556 |
done |
|
557 |
# error if the module could not be found |
|
558 |
if [ -z $moduleidx ]; then |
|
559 |
printError "module ($module) not available\n" |
|
560 |
return -2 |
|
561 |
fi |
|
562 |
fi |
|
551 | 563 |
|
552 | 564 |
# read absolute project directory if required |
553 | 565 |
if [ -z "$projectdir" ]; then |
554 | 566 |
getProjectDir projectdir |
567 |
printf "\n" |
|
568 |
fi |
|
569 |
|
|
570 |
# check for existing project files |
|
571 |
local projectfiles="$(find ${projectdir} -maxdepth 1 -type f | grep -E "${module}\.(includes|files|config|creator)$")" |
|
572 |
IFS=$'\n'; projectfiles=($projectfiles); unset IFS |
|
573 |
if [ ! -z "${projectfiles[*]}" ]; then |
|
574 |
printWarning "The following files will be overwritten:\n" |
|
575 |
for pfile in ${projectfiles[@]}; do |
|
576 |
printWarning "\t$(basename $pfile)\n" |
|
577 |
done |
|
578 |
local userinput="" |
|
579 |
printInfo "Continue and overwrite? [y/n]\n" |
|
580 |
readUserInput "YyNn" userinput |
|
581 |
case "$userinput" in |
|
582 |
Y|y) |
|
583 |
;; |
|
584 |
N|n) |
|
585 |
printWarning "Project generation for ${module} module aborted by user\n" |
|
586 |
return 1 |
|
587 |
;; |
|
588 |
*) |
|
589 |
printError "unexpected input: ${userinput}\n"; return -999;; |
|
590 |
esac |
|
591 |
printf "\n" |
|
555 | 592 |
fi |
556 | 593 |
|
557 |
# retrieve absolute GCC include dir |
|
594 |
# print message |
|
595 |
printInfo "generating QtCreator project files for the $module module...\n" |
|
596 |
|
|
597 |
# retrieve absolute GCC include path |
|
558 | 598 |
if [ -z "$gccincludedir" ]; then |
559 | 599 |
retrieveGccIncludeDir gccincludedir |
560 | 600 |
fi |
561 | 601 |
|
562 |
# move to project directory |
|
563 |
cd $projectdir |
|
564 |
|
|
565 |
# create project files |
|
566 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
|
567 |
find $gccincludedir -type d > ${projectdir}/LightRing.includes |
|
568 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Source) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/LightRing.includes |
|
569 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Modules/LightRing_1-0/Boot) -type d | grep -v "bin\|cmd\|ethernetlib\|fatfs\|uip\|obj" >> ${projectdir}/LightRing.includes |
|
570 |
# generate a file that specifies all files |
|
571 |
echo -n "" > ${projectdir}/LightRing.files |
|
572 |
for path in `cat ${projectdir}/LightRing.includes`; do |
|
573 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/LightRing.files |
|
602 |
# change to project directory |
|
603 |
local amirobltrootdir=$(realpath $(dirname ${BASH_SOURCE[0]})/../../..) |
|
604 |
cd "$projectdir" |
|
605 |
|
|
606 |
# run make, but only run the GCC preprocessor and produce no binaries |
|
607 |
local sourcefiles=() |
|
608 |
local sourcefile="" |
|
609 |
local parse_state="WAIT_FOR_INCLUDE_OR_COMPILE" |
|
610 |
# capture all output from make and GCC and append the return value of make as last line |
|
611 |
printInfo "processing project (this may take a while)...\n" |
|
612 |
local rawout=$(make --directory ${amirobltrootdir}/Target/Modules/${module}/Boot --always-make USER_CFLAGS="-v -H" 2>&1 && echo $?) |
|
613 |
# check whether the make call was successfull |
|
614 |
if [[ $(echo "${rawout}" | tail -n 1) != "0" ]]; then |
|
615 |
printError "executing 'make' in module directory failed\n" |
|
616 |
cd "$userdir" |
|
617 |
return -3 |
|
618 |
fi |
|
619 |
# extract file names from raw output |
|
620 |
IFS=$'\n'; rawout=($rawout); unset IFS |
|
621 |
for line in "${rawout[@]}"; do |
|
622 |
case $parse_state in |
|
623 |
WAIT_FOR_INCLUDE_OR_COMPILE) |
|
624 |
# lines stating included files look like: |
|
625 |
# ... <../relative/path/to/file> |
|
626 |
if [[ "$line" =~ ^\.+[[:blank:]].+\..+$ ]]; then |
|
627 |
sourcefile=${line##* } |
|
628 |
if [[ ! "$sourcefile" =~ ^/ ]]; then |
|
629 |
sourcefile=$(realpath ${amirobltrootdir}/Target/Modules/${module}/Boot/${sourcefile}) |
|
630 |
fi |
|
631 |
sourcefiles[${#sourcefiles[@]}]="$sourcefile" |
|
632 |
# whenever the next source file is processed, a message appears like: |
|
633 |
# Compining <filnemame> |
|
634 |
elif [[ "$line" =~ ^\+\+\+[[:blank:]]Compiling[[:blank:]]\[(.+\.c)\]$ ]]; then |
|
635 |
printf "." |
|
636 |
sourcefile=${BASH_REMATCH[1]} |
|
637 |
parse_state="WAIT_FOR_COMPILERCALL" |
|
638 |
fi;; |
|
639 |
WAIT_FOR_COMPILERCALL) |
|
640 |
# wait for the actual call of the compiler to retrieve the full path to the source file |
|
641 |
if [[ "$line" == *${sourcefile}* ]]; then |
|
642 |
line="${line%%${sourcefile}*}${sourcefile}" |
|
643 |
sourcefile=$(realpath ${amirobltrootdir}/Target/Modules/${module}/Boot/${line##* }) |
|
644 |
sourcefiles[${#sourcefiles[@]}]="$sourcefile" |
|
645 |
parse_state="WAIT_FOR_INCLUDE_OR_COMPILE" |
|
646 |
fi;; |
|
647 |
esac |
|
648 |
done |
|
649 |
unset rawout |
|
650 |
printf "\n" |
|
651 |
# sort and remove duplicates |
|
652 |
IFS=$'\n'; sourcefiles=($(sort --unique <<< "${sourcefiles[*]}")); unset IFS |
|
653 |
|
|
654 |
# extract include paths |
|
655 |
local includes=() |
|
656 |
for source in ${sourcefiles[*]}; do |
|
657 |
includes[${#includes[@]}]="$(dirname ${source})" |
|
658 |
done |
|
659 |
# sort and remove duplicates |
|
660 |
IFS=$'\n'; includes=($(sort --unique <<< "${includes[*]}")); unset IFS |
|
661 |
|
|
662 |
# generate the .files file, containing all source files |
|
663 |
echo "" > ${projectdir}/${module}.includes |
|
664 |
for inc in ${includes[*]}; do |
|
665 |
echo "$inc" >> ${projectdir}/${module}.includes |
|
574 | 666 |
done |
575 |
# generate a default project configuration file if none exists so far |
|
576 |
if [ ! -f ${projectdir}/LightRing.config ]; then |
|
577 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/LightRing.config |
|
578 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/LightRing.config |
|
579 |
echo -e "" >> ${projectdir}/LightRing.config |
|
667 |
# generate the .incldues file, containing all include paths |
|
668 |
echo "" > ${projectdir}/${module}.files |
|
669 |
for source in ${sourcefiles[*]}; do |
|
670 |
# skip GCC files |
|
671 |
if [[ ! "$source" =~ .*/gcc.* ]]; then |
|
672 |
echo "$source" >> ${projectdir}/${module}.files |
|
673 |
fi |
|
674 |
done |
|
675 |
# generate a default project configuration file if it doesn't exist yet |
|
676 |
if [ ! -f ${projectdir}/${module}.config ]; then |
|
677 |
echo "// Add predefined macros for your project here. For example:" > ${projectdir}/${module}.config |
|
678 |
echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/${module}.config |
|
580 | 679 |
fi |
581 |
# generate a default .creator file if none exists so far |
|
582 |
if [ ! -f ${projectdir}/LightRing.creator ]; then |
|
583 |
echo -e "[general]" > ${projectdir}/LightRing.creator |
|
584 |
echo -e "" >> ${projectdir}/LightRing.creator |
|
680 |
# generate a default .creator file if it doesn't exist yet |
|
681 |
if [ ! -f ${projectdir}/${module}.creator ]; then |
|
682 |
echo "[general]" > ${projectdir}/${module}.creator |
|
585 | 683 |
fi |
586 | 684 |
|
587 | 685 |
# go back to user directory |
... | ... | |
598 | 696 |
return 0 |
599 | 697 |
} |
600 | 698 |
|
601 |
### create PowerManagement project files #######################################
|
|
602 |
# Create project files for the PowerManagement module.
|
|
699 |
### create project files for all modules #######################################
|
|
700 |
# Create project files for all modules.
|
|
603 | 701 |
# |
604 |
# usage: createPowerManagementProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
|
605 |
# arguments: -p, --path <path> |
|
702 |
# usage: createAllProjects <modules> [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
|
703 |
# arguments: <modules> |
|
704 |
# Array containing all modules available. |
|
705 |
# -p, --path <path> |
|
606 | 706 |
# Path where to create the project files. |
607 | 707 |
# --gcc=<path> |
608 | 708 |
# Path to the GCC include directory. |
... | ... | |
610 | 710 |
# Variable to store the path to. |
611 | 711 |
# --gccout=<var> |
612 | 712 |
# Variable to store the path to the GCC include directory to. |
713 |
# If this optional arguments is absent, ths function will ask for user input. |
|
613 | 714 |
# return: 0 |
614 | 715 |
# No error or warning occurred. |
716 |
# 1 |
|
717 |
# Aborted by user. |
|
718 |
# -1 |
|
719 |
# No modules available. |
|
615 | 720 |
# |
616 |
function createPowerManagementProject {
|
|
617 |
local userdir=$(pwd)
|
|
721 |
function createAllProjects {
|
|
722 |
local modules=("${!1}")
|
|
618 | 723 |
local projectdir="" |
619 | 724 |
local gccincludedir="" |
620 | 725 |
local outvar="" |
... | ... | |
650 | 755 |
fi |
651 | 756 |
done |
652 | 757 |
|
653 |
# print message |
|
654 |
printInfo "creating QtCreator project files for the PowerManagement module...\n" |
|
758 |
# sanity check for the modules variable |
|
759 |
if [ -z "${modules[*]}" ]; then |
|
760 |
printError "no modules available\n" |
|
761 |
return -1 |
|
762 |
fi |
|
655 | 763 |
|
656 | 764 |
# read absolute project directory if required |
657 | 765 |
if [ -z "$projectdir" ]; then |
658 | 766 |
getProjectDir projectdir |
659 | 767 |
fi |
660 | 768 |
|
661 |
# retrieve absolute GCC include dir |
|
662 |
if [ -z "$gccincludedir" ]; then |
|
663 |
retrieveGccIncludeDir gccincludedir |
|
664 |
fi |
|
665 |
|
|
666 |
# move to project directory |
|
667 |
cd $projectdir |
|
668 |
|
|
669 |
# create project files |
|
670 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
|
671 |
find $gccincludedir -type d > ${projectdir}/PowerManagement.includes |
|
672 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Source) -type d | grep -v "ARMCM3_STM32" >> ${projectdir}/PowerManagement.includes |
|
673 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Modules/PowerManagement_1-1/Boot) -type d | grep -v "bin\|cmd\|ethernetlib\|fatfs\|uip\|obj" >> ${projectdir}/PowerManagement.includes |
|
674 |
# generate a file that specifies all files |
|
675 |
echo -n "" > ${projectdir}/PowerManagement.files |
|
676 |
for path in `cat ${projectdir}/PowerManagement.includes`; do |
|
677 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/PowerManagement.files |
|
769 |
# check for existing project files |
|
770 |
local projectfiles=() |
|
771 |
for module in ${modules[@]}; do |
|
772 |
local pfiles="$(find ${projectdir} -maxdepth 1 -type f | grep -E "${module}\.(includes|files|config|creator)$")" |
|
773 |
IFS=$'\n'; pfiles=($pfiles); unset IFS |
|
774 |
projectfiles=( ${projectfiles[*]} ${pfiles[*]} ) |
|
678 | 775 |
done |
679 |
# generate a default project configuration file if none exists so far |
|
680 |
if [ ! -f ${projectdir}/PowerManagement.config ]; then |
|
681 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/PowerManagement.config |
|
682 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/PowerManagement.config |
|
683 |
echo -e "" >> ${projectdir}/PowerManagement.config |
|
684 |
fi |
|
685 |
# generate a default .creator file if none exists so far |
|
686 |
if [ ! -f ${projectdir}/PowerManagement.creator ]; then |
|
687 |
echo -e "[general]" > ${projectdir}/PowerManagement.creator |
|
688 |
echo -e "" >> ${projectdir}/PowerManagement.creator |
|
776 |
if [ ! -z "${projectfiles[*]}" ]; then |
|
777 |
printWarning "The following files will be removed:\n" |
|
778 |
for pfile in ${projectfiles[@]}; do |
|
779 |
printWarning "\t$(basename $pfile)\n" |
|
780 |
done |
|
781 |
local userinput="" |
|
782 |
printInfo "Continue and overwrite? [y/n]\n" |
|
783 |
readUserInput "YyNn" userinput |
|
784 |
case "${userinput}" in |
|
785 |
Y|y) |
|
786 |
for pfile in ${projectfiles[*]}; do |
|
787 |
rm "$pfile" |
|
788 |
done |
|
789 |
;; |
|
790 |
N|n) |
|
791 |
printWarning "Project generation aborted by user\n" |
|
792 |
return 1 |
|
793 |
;; |
|
794 |
*) |
|
795 |
printError "unexpected input: ${userinput}\n" |
|
796 |
return 999 |
|
797 |
;; |
|
798 |
esac |
|
689 | 799 |
fi |
690 | 800 |
|
691 |
# go back to user directory
|
|
692 |
cd $userdir
|
|
693 |
|
|
801 |
# print message
|
|
802 |
printf "\n"
|
|
803 |
printInfo "generating QtCreator project files for all modules...\n" |
|
694 | 804 |
|
695 |
# fill the output variables |
|
696 |
if [ ! -z "$outvar" ]; then |
|
697 |
eval $outvar="$projectdir" |
|
698 |
fi |
|
699 |
if [ ! -z "$gccoutvar" ]; then |
|
700 |
eval $gccoutvar="$gccincludedir" |
|
805 |
# retrieve absolute GCC include path |
|
806 |
if [ -z "$gccincludedir" ]; then |
|
807 |
retrieveGccIncludeDir gccincludedir |
|
701 | 808 |
fi |
702 | 809 |
|
810 |
# iterate over all modules |
|
811 |
local retval=1 |
|
812 |
for module in ${modules[@]}; do |
|
813 |
if [ $retval != 0 ]; then |
|
814 |
printf "\n" |
|
815 |
fi |
|
816 |
createModuleProject modules[@] --module="$module" --path="$projectdir" --gcc="$gccincludedir" |
|
817 |
retval=$? |
|
818 |
done |
|
819 |
|
|
703 | 820 |
return 0 |
704 | 821 |
} |
705 | 822 |
|
706 |
### create DiWheelDrive project files ##########################################
|
|
707 |
# Create project files for the DiWheelDrive module.
|
|
823 |
### delete project files #######################################################
|
|
824 |
# Deletes all project files and optionally .user files, too.
|
|
708 | 825 |
# |
709 |
# usage: createDiWheelDriveProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
|
|
826 |
# usage: deleteProjects [-p|--path=<path>] [-m|--module=<module>] [-o|--out=<var>] [-w|-wipe]
|
|
710 | 827 |
# arguments: -p, --path <path> |
711 |
# Path where to create the project files.
|
|
712 |
# --gcc=<path>
|
|
713 |
# Path to the GCC include directory.
|
|
828 |
# Path where to delete the project files.
|
|
829 |
# -m, --module <module>
|
|
830 |
# Module name for which the project files shall be deleted.
|
|
714 | 831 |
# -o, --out <var> |
715 | 832 |
# Variable to store the path to. |
716 |
# --gccout=<var>
|
|
717 |
# Variable to store the path to the GCC include directory to.
|
|
718 |
# return: 0
|
|
719 |
# No error or warning occurred.
|
|
833 |
# -w, --wipe
|
|
834 |
# Delete .user files as well.
|
|
835 |
# return: |
|
836 |
# - 0: no error
|
|
720 | 837 |
# |
721 |
function createDiWheelDriveProject {
|
|
722 |
local userdir=$(pwd)
|
|
838 |
function deleteProjects {
|
|
839 |
local modulename=""
|
|
723 | 840 |
local projectdir="" |
724 |
local gccincludedir="" |
|
725 | 841 |
local outvar="" |
726 |
local gccoutvar="" |
|
842 |
local wipe=false |
|
843 |
local files="" |
|
727 | 844 |
|
728 | 845 |
# parse arguments |
729 | 846 |
local otherargs=() |
... | ... | |
734 | 851 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
735 | 852 |
-p|--path) |
736 | 853 |
projectdir=$(realpath "$2"); shift 2;; |
737 |
--gcc=*)
|
|
738 |
gccincludedir=$(realpath "${1#*=}"); shift 1;;
|
|
739 |
--gcc)
|
|
740 |
gccincludedir=$(realpath "$2"); shift 2;;
|
|
854 |
-m=*|--module=*)
|
|
855 |
modulename="${1#*=}"; shift 1;;
|
|
856 |
-m|--module)
|
|
857 |
modulename="${2}"; shift 2;;
|
|
741 | 858 |
-o=*|--out=*) |
742 | 859 |
outvar=${1#*=}; shift 1;; |
743 | 860 |
-o|--out) |
744 | 861 |
outvar=$2; shift 2;; |
745 |
--gccout=*) |
|
746 |
gccoutvar=$(realpath "${1#*=}"); shift 1;; |
|
747 |
--gccout) |
|
748 |
gccoutvar=$(realpath "$2"); shift 2;; |
|
862 |
-w|--wipe) |
|
863 |
wipe=true; shift 1;; |
|
749 | 864 |
*) |
750 | 865 |
printError "invalid option: $1\n"; shift 1;; |
751 | 866 |
esac |
... | ... | |
755 | 870 |
fi |
756 | 871 |
done |
757 | 872 |
|
758 |
# print message |
|
759 |
printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
|
760 |
|
|
761 | 873 |
# read absolute project directory if required |
762 | 874 |
if [ -z "$projectdir" ]; then |
763 | 875 |
getProjectDir projectdir |
764 | 876 |
fi |
765 | 877 |
|
766 |
# retrieve absolute GCC include dir |
|
767 |
if [ -z "$gccincludedir" ]; then |
|
768 |
retrieveGccIncludeDir gccincludedir |
|
769 |
fi |
|
770 |
|
|
771 |
# move to project directory |
|
772 |
cd $projectdir |
|
773 |
|
|
774 |
|
|
775 |
# create project files |
|
776 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
|
777 |
find $gccincludedir -type d > ${projectdir}/DiWheelDrive.includes |
|
778 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Source) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/DiWheelDrive.includes |
|
779 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Modules/DiWheelDrive_1-1/Boot) -type d | grep -v "bin\|cmd\|ethernetlib\|fatfs\|uip\|obj" >> ${projectdir}/DiWheelDrive.includes |
|
780 |
# generate a file that specifies all files |
|
781 |
echo -n "" > ${projectdir}/DiWheelDrive.files |
|
782 |
for path in `cat ${projectdir}/DiWheelDrive.includes`; do |
|
783 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/DiWheelDrive.files |
|
784 |
done |
|
785 |
# generate a default project configuration file if none exists so far |
|
786 |
if [ ! -f ${projectdir}/DiWheelDrive.config ]; then |
|
787 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/DiWheelDrive.config |
|
788 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/DiWheelDrive.config |
|
789 |
echo -e "" >> ${projectdir}/DiWheelDrive.config |
|
878 |
# list all files to be deleted |
|
879 |
if [ -z "$modulename" ]; then |
|
880 |
if [ $wipe != true ]; then |
|
881 |
files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator|cflags|cxxflags)$") |
|
882 |
else |
|
883 |
files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator|cflags|cxxflags|creator(\.user(\..+)?)?)$") |
|
884 |
fi |
|
885 |
else |
|
886 |
if [ $wipe != true ]; then |
|
887 |
files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^${modulename}\.(includes|files|config|creator|cflags|cxxflags)$") |
|
888 |
else |
|
889 |
files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^${modulename}\.(includes|files|config|creator|cflags|cxxflags|creator(\.user(\..+)?)?)$") |
|
890 |
fi |
|
790 | 891 |
fi |
791 |
# generate a default .creator file if none exists so far |
|
792 |
if [ ! -f ${projectdir}/DiWheelDrive.creator ]; then |
|
793 |
echo -e "[general]" > ${projectdir}/DiWheelDrive.creator |
|
794 |
echo -e "" >> ${projectdir}/DiWheelDrive.creator |
|
892 |
if [ ! -z "$files" ]; then |
|
893 |
printInfo "Deleting the following files:\n" |
|
894 |
while read line; do |
|
895 |
printInfo "\t$(basename ${line})\n" |
|
896 |
rm ${line} 2>&1 | tee -a $LOG_FILE |
|
897 |
done <<< "${files}" |
|
898 |
else |
|
899 |
printInfo "No project files found\n" |
|
795 | 900 |
fi |
796 | 901 |
|
797 |
# go back to user directory |
|
798 |
cd $userdir |
|
799 |
|
|
800 |
|
|
801 |
# fill the output variables |
|
902 |
# store the path to the output variable, if required |
|
802 | 903 |
if [ ! -z "$outvar" ]; then |
803 | 904 |
eval $outvar="$projectdir" |
804 | 905 |
fi |
805 |
if [ ! -z "$gccoutvar" ]; then |
|
806 |
eval $gccoutvar="$gccincludedir" |
|
807 |
fi |
|
808 |
|
|
809 |
return 0 |
|
810 |
} |
|
811 |
|
|
812 |
### create project files for al modules ######################################## |
|
813 |
# Create project files for all modules. |
|
814 |
# |
|
815 |
# usage: createAllProjects |
|
816 |
# arguments: n/a |
|
817 |
# return: 0 |
|
818 |
# No error or warning occurred. |
|
819 |
# |
|
820 |
function createAllProjects { |
|
821 |
# print message |
|
822 |
printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
|
823 |
|
|
824 |
# read project directory |
|
825 |
local projectdir="" |
|
826 |
getProjectDir projectdir |
|
827 |
printInfo "files will be created in $projectdir\n" |
|
828 |
|
|
829 |
# retrieve gcc-arm-none-eabi include dir |
|
830 |
retrieveGccIncludeDir gccincludedir |
|
831 |
|
|
832 |
# create projects |
|
833 |
createLightRingProject --path="$projectdir" --gcc="$gccincludedir" |
|
834 |
createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir" |
|
835 |
createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir" |
|
836 | 906 |
|
837 | 907 |
return 0 |
838 | 908 |
} |
... | ... | |
887 | 957 |
# log script name |
888 | 958 |
printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
889 | 959 |
|
960 |
# detect available modules and inform user |
|
961 |
local modules=() |
|
962 |
detectModules modules |
|
963 |
case "${#modules[@]}" in |
|
964 |
0) |
|
965 |
printInfo "no module has been detected\n";; |
|
966 |
1) |
|
967 |
printInfo "1 module has been detected:\n";; |
|
968 |
*) |
|
969 |
printInfo "${#modules[@]} modules have been detected:\n" |
|
970 |
esac |
|
971 |
for (( idx=0; idx<${#modules[@]}; ++idx )); do |
|
972 |
printInfo " - ${modules[$idx]}\n" |
|
973 |
done |
|
974 |
printf "\n" |
|
975 |
|
|
890 | 976 |
# parse arguments |
891 | 977 |
local otherargs=() |
892 | 978 |
while [ $# -gt 0 ]; do |
... | ... | |
894 | 980 |
case "$1" in |
895 | 981 |
-h|--help) # already handled; ignore |
896 | 982 |
shift 1;; |
983 |
-m=*|--module=*) |
|
984 |
createModuleProject modules[@] --module="${1#*=}"; printf "\n"; shift 1;; |
|
985 |
-m|--module) |
|
986 |
createModuleProject modules[@] --module="${2}"; printf "\n"; shift 2;; |
|
987 |
-a|--all) |
|
988 |
createAllProjects modules[@]; shift 1;; |
|
897 | 989 |
-c|--clean) |
898 | 990 |
deleteProjects; printf "\n"; shift 1;; |
899 | 991 |
-w|--wipe) |
900 | 992 |
deleteProjects --wipe; printf "\n"; shift 1;; |
901 |
--LightRing) |
|
902 |
createLightRingProject; printf "\n"; shift 1;; |
|
903 |
--PowerManagement) |
|
904 |
createPowerManagementProject; printf "\n"; shift 1;; |
|
905 |
--DiWheelDrive) |
|
906 |
createDiWheelDriveProject; printf "\n"; shift 1;; |
|
907 |
-a|--all) |
|
908 |
createAllProjects; printf "\n"; shift 1;; |
|
909 | 993 |
-q|--quit) |
910 | 994 |
quitScript; shift 1;; |
911 | 995 |
--log=*|--LOG=*) # already handled; ignore |
... | ... | |
923 | 1007 |
fi |
924 | 1008 |
done |
925 | 1009 |
|
926 |
# interactive menu |
|
1010 |
# interactive menu
|
|
927 | 1011 |
while ( true ); do |
928 | 1012 |
# main menu info prompt and selection |
929 | 1013 |
printInfo "QtCreator setup main menu\n" |
930 | 1014 |
printf "Please select one of the following actions:\n" |
931 |
printf " [C] - clean project files\n" |
|
932 |
printf " [W] - wipe project and .user files\n" |
|
933 |
printf " [L] - create a project for the LightRing module\n" |
|
934 |
printf " [P] - create a project for the PowerManagement module\n" |
|
935 |
printf " [D] - create a project for the DiWheelDrive module\n" |
|
1015 |
printf " [M] - create a project for a single module\n" |
|
936 | 1016 |
printf " [A] - create a project for all modules\n" |
1017 |
printf " [C] - clean all project files\n" |
|
1018 |
printf " [W] - wipe all project and .user files\n" |
|
937 | 1019 |
printf " [Q] - quit this setup\n" |
938 | 1020 |
local userinput="" |
939 |
readUserInput "CcWwLlPpDdAaQq" userinput
|
|
1021 |
readUserInput "MmAaCcWwQq" userinput
|
|
940 | 1022 |
printf "\n" |
941 | 1023 |
|
942 | 1024 |
# evaluate user selection |
943 | 1025 |
case "$userinput" in |
1026 |
M|m) |
|
1027 |
createModuleProject modules[@]; printf "\n";; |
|
1028 |
A|a) |
|
1029 |
createAllProjects modules[@]; printf "\n";; |
|
944 | 1030 |
C|c) |
945 | 1031 |
deleteProjects; printf "\n";; |
946 | 1032 |
W|w) |
947 | 1033 |
deleteProjects --wipe; printf "\n";; |
948 |
L|l) |
|
949 |
createLightRingProject; printf "\n";; |
|
950 |
P|p) |
|
951 |
createPowerManagementProject; printf "\n";; |
|
952 |
D|d) |
|
953 |
createDiWheelDriveProject; printf "\n";; |
|
954 |
A|a) |
|
955 |
createAllProjects; printf "\n";; |
|
956 | 1034 |
Q|q) |
957 | 1035 |
quitScript;; |
958 | 1036 |
*) # sanity check (exit with error) |
Also available in: Unified diff