amiro-blt / ide / QtCreator / QtCreatorSetup.sh @ 3719a40a
History | View | Annotate | Download (31.581 KB)
| 1 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
|---|---|---|---|
| 2 | 1da30dfc | Thomas Schöpping | # AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini # |
| 3 | # Robot (AMiRo) platform. # |
||
| 4 | 4cce70a8 | Thomas Schöpping | # Copyright (C) 2016..2017 Thomas Schöpping et al. # |
| 5 | # # |
||
| 6 | # This program is free software: you can redistribute it and/or modify # |
||
| 7 | # it under the terms of the GNU General Public License as published by # |
||
| 8 | # the Free Software Foundation, either version 3 of the License, or # |
||
| 9 | # (at your option) any later version. # |
||
| 10 | # # |
||
| 11 | # This program is distributed in the hope that it will be useful, # |
||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # |
||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
||
| 14 | # GNU General Public License for more details. # |
||
| 15 | # # |
||
| 16 | # You should have received a copy of the GNU General Public License # |
||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # |
||
| 18 | # # |
||
| 19 | # This research/work was supported by the Cluster of Excellence Cognitive # |
||
| 20 | # Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is # |
||
| 21 | # funded by the German Research Foundation (DFG). # |
||
| 22 | ################################################################################ |
||
| 23 | |||
| 24 | 69661903 | Thomas Schöpping | #!/bin/bash |
| 25 | |||
| 26 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 27 | 1da30dfc | Thomas Schöpping | # GENERIC FUNCTIONS # |
| 28 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 29 | 69661903 | Thomas Schöpping | |
| 30 | 0a42f078 | Thomas Schöpping | ### print an error message ##################################################### |
| 31 | # Prints a error <message> to standard output. |
||
| 32 | #If variable 'LOG_FILE' is specified, the message is also appended to the given file. |
||
| 33 | # |
||
| 34 | # usage: printError <message> |
||
| 35 | # arguments: <message> |
||
| 36 | # Message string to print. |
||
| 37 | # return: n/a |
||
| 38 | # |
||
| 39 | 1da30dfc | Thomas Schöpping | function printError {
|
| 40 | local string="ERROR: $1" |
||
| 41 | # if a log file is specified |
||
| 42 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
| 43 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
| 44 | 69661903 | Thomas Schöpping | fi |
| 45 | 1da30dfc | Thomas Schöpping | printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2 |
| 46 | } |
||
| 47 | 69661903 | Thomas Schöpping | |
| 48 | 0a42f078 | Thomas Schöpping | ### print a warning message #################################################### |
| 49 | # Prints a warning <message> to standard output. |
||
| 50 | #If variable 'LOG_FILE' is specified, the message is also appended to the given file. |
||
| 51 | # |
||
| 52 | # usage: printMessage <message> |
||
| 53 | # arguments: <message> |
||
| 54 | # Message string to print. |
||
| 55 | # return: n/a |
||
| 56 | # |
||
| 57 | 1da30dfc | Thomas Schöpping | function printWarning {
|
| 58 | local string="WARNING: $1" |
||
| 59 | # if a log file is specified |
||
| 60 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
| 61 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
| 62 | fi |
||
| 63 | 0a42f078 | Thomas Schöpping | printf "$(tput setaf 3)>>> $string$(tput sgr 0)" |
| 64 | 1da30dfc | Thomas Schöpping | } |
| 65 | |||
| 66 | 0a42f078 | Thomas Schöpping | ### print an information message ############################################### |
| 67 | # Prints an information <message> to standard output. |
||
| 68 | #If variable 'LOG_FILE' is specified, the message is also appended to the given file. |
||
| 69 | # |
||
| 70 | # usage: printInfo <message> |
||
| 71 | # arguments: <message> |
||
| 72 | # Message string to print. |
||
| 73 | # return: n/a |
||
| 74 | # |
||
| 75 | 1da30dfc | Thomas Schöpping | function printInfo {
|
| 76 | local string="INFO: $1" |
||
| 77 | # if a log file is specified |
||
| 78 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
| 79 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
| 80 | fi |
||
| 81 | 0a42f078 | Thomas Schöpping | printf "$(tput setaf 2)>>> $string$(tput sgr 0)" |
| 82 | 1da30dfc | Thomas Schöpping | } |
| 83 | |||
| 84 | 0a42f078 | Thomas Schöpping | ### print a message to file #################################################### |
| 85 | # Appends a <message> to a log file, specified by the variable 'LOG_FILE'. |
||
| 86 | # |
||
| 87 | # usage printLog <message> |
||
| 88 | # arguments: <message> |
||
| 89 | # Message string to print. |
||
| 90 | # return: n/a |
||
| 91 | # |
||
| 92 | 1da30dfc | Thomas Schöpping | function printLog {
|
| 93 | local string="LOG: $1" |
||
| 94 | # if a log file is specified |
||
| 95 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
| 96 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
| 97 | 69661903 | Thomas Schöpping | fi |
| 98 | 1da30dfc | Thomas Schöpping | } |
| 99 | |||
| 100 | 0a42f078 | Thomas Schöpping | ### exit the script normally ################################################### |
| 101 | # Prints a delimiter and exits the script normally (returns 0). |
||
| 102 | # |
||
| 103 | # usage: quitScript |
||
| 104 | # arguments: n/a |
||
| 105 | # return: 0 |
||
| 106 | # No error or warning occurred. |
||
| 107 | # |
||
| 108 | 1da30dfc | Thomas Schöpping | function quitScript {
|
| 109 | 3719a40a | Thomas Schöpping | printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n"
|
| 110 | printf "\n" |
||
| 111 | 1da30dfc | Thomas Schöpping | printf "######################################################################\n" |
| 112 | exit 0 |
||
| 113 | 69661903 | Thomas Schöpping | } |
| 114 | |||
| 115 | 0a42f078 | Thomas Schöpping | ### read a user input ########################################################## |
| 116 | # Reads a single character user input from a set up <options> and stores it in |
||
| 117 | # a given <return> variable. |
||
| 118 | # |
||
| 119 | # usage: readUserInput <options> <return> |
||
| 120 | # arguments: <options> |
||
| 121 | # String definiing the set of valid characters. |
||
| 122 | # If the string is empty, the user can input any character. |
||
| 123 | # <return> |
||
| 124 | # Variable to store the selected character to. |
||
| 125 | # return: n/a |
||
| 126 | # |
||
| 127 | 1da30dfc | Thomas Schöpping | function readUserInput {
|
| 128 | 0a42f078 | Thomas Schöpping | local input="" |
| 129 | 1da30dfc | Thomas Schöpping | # read user input |
| 130 | 0a42f078 | Thomas Schöpping | while [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); do |
| 131 | read -p "your selection: " -n 1 -e input |
||
| 132 | if [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); then |
||
| 133 | printWarning "[$input] is no valid action\n" |
||
| 134 | 69661903 | Thomas Schöpping | fi |
| 135 | done |
||
| 136 | 0a42f078 | Thomas Schöpping | printLog "[$input] has been selected\n" |
| 137 | eval $2="$input" |
||
| 138 | 1da30dfc | Thomas Schöpping | } |
| 139 | 69661903 | Thomas Schöpping | |
| 140 | 0a42f078 | Thomas Schöpping | ### check whether argument is an option ######################################## |
| 141 | # Checks a <string> whether it is an option. |
||
| 142 | # Options are defined to either start with '--' followed by any string, or |
||
| 143 | # to start with a single '-' followed by a single character, or |
||
| 144 | # to start with a single '-' followed by a single character, a '=' and any string. |
||
| 145 | # Examples: '--option', '--option=arg', '-o', '-o=arg', '--' |
||
| 146 | # |
||
| 147 | # usage: parseIsOption <string> |
||
| 148 | # arguments: <string> |
||
| 149 | # A string to check whether it is an option. |
||
| 150 | # return: 0 |
||
| 151 | # <string> is an option. |
||
| 152 | # -1 |
||
| 153 | # <string> is not an option. |
||
| 154 | # |
||
| 155 | function parseIsOption {
|
||
| 156 | if [[ "$1" =~ ^-(.$|.=.*) ]] || [[ "$1" =~ ^--.* ]]; then |
||
| 157 | return 0 |
||
| 158 | else |
||
| 159 | 1da30dfc | Thomas Schöpping | return -1 |
| 160 | 69661903 | Thomas Schöpping | fi |
| 161 | 0a42f078 | Thomas Schöpping | } |
| 162 | 1da30dfc | Thomas Schöpping | |
| 163 | 0a42f078 | Thomas Schöpping | ### set the log file ########################################################### |
| 164 | # Sets a specified <infile> as log file and checks whether it already exists. |
||
| 165 | # If so, the log may either be appended to the file, its content can be cleared, |
||
| 166 | # or no log is generated at all. |
||
| 167 | # The resulting path is stored in <outvar>. |
||
| 168 | # |
||
| 169 | # usage: setLogFile [--option=<option>] [--quiet] <infile> <outvar> |
||
| 170 | # arguments: --option=<option> |
||
| 171 | # Select what to do if <file> already exists. |
||
| 172 | # Possible values are 'a', 'r' and 'n'. |
||
| 173 | # - a: append |
||
| 174 | # - r: delete and restart |
||
| 175 | # - n: no log |
||
| 176 | # If no option is secified but <file> exists, an interactive selection is provided. |
||
| 177 | # --quiet |
||
| 178 | # Suppress all messages. |
||
| 179 | # <infile> |
||
| 180 | # Path of the wanted log file. |
||
| 181 | # <outvar> |
||
| 182 | # Variable to store the path of the log file to. |
||
| 183 | # return: 0 |
||
| 184 | # No error or warning occurred. |
||
| 185 | # -1 |
||
| 186 | # Error: invalid input |
||
| 187 | # |
||
| 188 | function setLogFile {
|
||
| 189 | local filepath="" |
||
| 190 | 1da30dfc | Thomas Schöpping | local option="" |
| 191 | 0a42f078 | Thomas Schöpping | local quiet=false |
| 192 | |||
| 193 | # parse arguments |
||
| 194 | local otherargs=() |
||
| 195 | while [ $# -gt 0 ]; do |
||
| 196 | if ( parseIsOption $1 ); then |
||
| 197 | case "$1" in |
||
| 198 | -o=*|--option=*) |
||
| 199 | option=${1#*=}; shift 1;;
|
||
| 200 | -o*|--option*) |
||
| 201 | option="$2"; shift 2;; |
||
| 202 | -q|--quiet) |
||
| 203 | quiet=true; shift 1;; |
||
| 204 | *) |
||
| 205 | printError "invalid option: $1\n"; shift 1;; |
||
| 206 | esac |
||
| 207 | else |
||
| 208 | otherargs+=("$1")
|
||
| 209 | shift 1 |
||
| 210 | fi |
||
| 211 | 1da30dfc | Thomas Schöpping | done |
| 212 | 0a42f078 | Thomas Schöpping | filepath=$(realpath ${otherargs[0]})
|
| 213 | 69661903 | Thomas Schöpping | |
| 214 | 1da30dfc | Thomas Schöpping | # if file already exists |
| 215 | 0a42f078 | Thomas Schöpping | if [ -e $filepath ]; then |
| 216 | 1da30dfc | Thomas Schöpping | # if no option was specified, ask what to do |
| 217 | 0a42f078 | Thomas Schöpping | if [ -z "$option" ]; then |
| 218 | printWarning "log file $filepath already esists\n" |
||
| 219 | local userinput="" |
||
| 220 | printf "Select what to do:\n" |
||
| 221 | 1da30dfc | Thomas Schöpping | printf " [A] - append log\n" |
| 222 | printf " [R] - restart log (delete existing file)\n" |
||
| 223 | printf " [N] - no log\n" |
||
| 224 | 0a42f078 | Thomas Schöpping | readUserInput "AaRrNn" userinput |
| 225 | 1da30dfc | Thomas Schöpping | option=${userinput,,}
|
| 226 | fi |
||
| 227 | # evaluate option |
||
| 228 | 0a42f078 | Thomas Schöpping | case "$option" in |
| 229 | 1da30dfc | Thomas Schöpping | a) |
| 230 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
| 231 | printInfo "appending log to $filepath\n" |
||
| 232 | fi |
||
| 233 | printf "\n" >> $filepath |
||
| 234 | printf "######################################################################\n" >> $filepath |
||
| 235 | printf "\n" >> $filepath |
||
| 236 | 1da30dfc | Thomas Schöpping | ;; |
| 237 | r) |
||
| 238 | 0a42f078 | Thomas Schöpping | echo -n "" > $filepath |
| 239 | if [ $quiet = false ]; then |
||
| 240 | printInfo "content of $filepath wiped\n" |
||
| 241 | fi |
||
| 242 | 1da30dfc | Thomas Schöpping | ;; |
| 243 | n) |
||
| 244 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
| 245 | printInfo "no log file will be generated\n" |
||
| 246 | fi |
||
| 247 | filepath="" |
||
| 248 | 1da30dfc | Thomas Schöpping | ;; |
| 249 | *) # sanity check (return error) |
||
| 250 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $option\n"; return -1;; |
| 251 | 1da30dfc | Thomas Schöpping | esac |
| 252 | 69661903 | Thomas Schöpping | else |
| 253 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
| 254 | printInfo "log file set to $filepath\n" |
||
| 255 | fi |
||
| 256 | 69661903 | Thomas Schöpping | fi |
| 257 | 0a42f078 | Thomas Schöpping | |
| 258 | eval ${otherargs[1]}="$filepath"
|
||
| 259 | |||
| 260 | return 0 |
||
| 261 | 69661903 | Thomas Schöpping | } |
| 262 | 4cce70a8 | Thomas Schöpping | |
| 263 | 1da30dfc | Thomas Schöpping | ################################################################################ |
| 264 | # SPECIFIC FUNCTIONS # |
||
| 265 | ################################################################################ |
||
| 266 | |||
| 267 | 0a42f078 | Thomas Schöpping | ### print welcome text ######################################################### |
| 268 | # Prints a welcome message to standard out. |
||
| 269 | # |
||
| 270 | # usage: printWelcomeText |
||
| 271 | # arguments: n/a |
||
| 272 | # return: n/a |
||
| 273 | # |
||
| 274 | 1da30dfc | Thomas Schöpping | function printWelcomeText {
|
| 275 | 4cce70a8 | Thomas Schöpping | printf "######################################################################\n" |
| 276 | printf "# #\n" |
||
| 277 | 1da30dfc | Thomas Schöpping | printf "# Welcome to the QtCreator setup! #\n" |
| 278 | 4cce70a8 | Thomas Schöpping | printf "# #\n" |
| 279 | printf "######################################################################\n" |
||
| 280 | printf "# #\n" |
||
| 281 | printf "# Copyright (c) 2016..2017 Thomas Schöpping #\n" |
||
| 282 | printf "# #\n" |
||
| 283 | printf "# This is free software; see the source for copying conditions. #\n" |
||
| 284 | printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
||
| 285 | printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
||
| 286 | printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
||
| 287 | printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
||
| 288 | printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
||
| 289 | printf "# Excellence Initiative. #\n" |
||
| 290 | printf "# #\n" |
||
| 291 | printf "######################################################################\n" |
||
| 292 | 1da30dfc | Thomas Schöpping | } |
| 293 | |||
| 294 | 0a42f078 | Thomas Schöpping | ### print help ################################################################# |
| 295 | # Prints a help text to standard out. |
||
| 296 | # |
||
| 297 | # usage: printHelp |
||
| 298 | # arguments: n/a |
||
| 299 | # return: n/a |
||
| 300 | # |
||
| 301 | 1da30dfc | Thomas Schöpping | function printHelp {
|
| 302 | printInfo "printing help text\n" |
||
| 303 | 0a42f078 | Thomas Schöpping | printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [--LightRing] [--PowerManagement] [--DiWheelDrive] [-a|--all] [-q|--quit] [--log=<file>]\n"
|
| 304 | printf "\n" |
||
| 305 | printf "options: -h, --help\n" |
||
| 306 | printf " Print this help text.\n" |
||
| 307 | printf " -c, --clean\n" |
||
| 308 | printf " Delete project files.\n" |
||
| 309 | printf " -w, --wipe\n" |
||
| 310 | printf " Delete project and .user files.\n" |
||
| 311 | printf " --LightRing\n" |
||
| 312 | printf " Create project for the LightRing module.\n" |
||
| 313 | printf " --PowerManagement\n" |
||
| 314 | printf " Create project for the PowerManagement module.\n" |
||
| 315 | printf " --DiWheelDrive\n" |
||
| 316 | printf " Create project for the DiWheelDrive module.\n" |
||
| 317 | printf " -a, --all\n" |
||
| 318 | printf " Create projects for all modules.\n" |
||
| 319 | printf " -q, --quit\n" |
||
| 320 | printf " Quit the script.\n" |
||
| 321 | printf " --log=<file>\n" |
||
| 322 | printf " Specify a log file.\n" |
||
| 323 | 1da30dfc | Thomas Schöpping | } |
| 324 | 69661903 | Thomas Schöpping | |
| 325 | 0a42f078 | Thomas Schöpping | ### read directory where to create/delete projects ############################# |
| 326 | # Read the directory where to create/delete project files from user. |
||
| 327 | # |
||
| 328 | # usage: getProjectDir <pathvar> |
||
| 329 | # arguments: <pathvar> |
||
| 330 | # Variable to store the selected path to. |
||
| 331 | # return: n/a |
||
| 332 | # |
||
| 333 | 1da30dfc | Thomas Schöpping | function getProjectDir {
|
| 334 | 0a42f078 | Thomas Schöpping | printLog "reading path for project files from user...\n" |
| 335 | local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../Target/)
|
||
| 336 | local input="" |
||
| 337 | read -p "Path where to create/delete project files: " -i $amirobltdir -e input |
||
| 338 | printLog "user selected path $(realpath $input)\n" |
||
| 339 | eval $1="$(realpath $input)" |
||
| 340 | 1da30dfc | Thomas Schöpping | } |
| 341 | 69661903 | Thomas Schöpping | |
| 342 | 0a42f078 | Thomas Schöpping | ### retrieves the ARM-NONE-EABI-GCC include directory ########################## |
| 343 | # Retrieves the include directory of the currently set arm-none-eabi-gcc. |
||
| 344 | # |
||
| 345 | # usage: retrieveGccIncludeDir <path> |
||
| 346 | # arguments: <path> |
||
| 347 | # Variable to store the path to. |
||
| 348 | # return: 0 |
||
| 349 | # No error or warning occurred. |
||
| 350 | # -1 |
||
| 351 | # Error: Command 'arm-none-eabi-gcc' not found. |
||
| 352 | # |
||
| 353 | 1da30dfc | Thomas Schöpping | function retrieveGccIncludeDir {
|
| 354 | # retrieve binary path or link |
||
| 355 | 0a42f078 | Thomas Schöpping | local binpath=$(which arm-none-eabi-gcc) |
| 356 | 1da30dfc | Thomas Schöpping | if [ -z "$binpath" ]; then |
| 357 | 0a42f078 | Thomas Schöpping | printError "command 'arm-none-eabi-gcc' not found\n" |
| 358 | 1da30dfc | Thomas Schöpping | return -1 |
| 359 | 0a42f078 | Thomas Schöpping | else |
| 360 | 69661903 | Thomas Schöpping | |
| 361 | 0a42f078 | Thomas Schöpping | # traverse any links |
| 362 | while [ -L "$binpath" ]; do |
||
| 363 | binpath=$(readlink $binpath) |
||
| 364 | done |
||
| 365 | printInfo "gcc-arm-none-eabi detected: $binpath\n" |
||
| 366 | 69661903 | Thomas Schöpping | |
| 367 | 0a42f078 | Thomas Schöpping | # return include path |
| 368 | eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
|
||
| 369 | 69661903 | Thomas Schöpping | |
| 370 | 0a42f078 | Thomas Schöpping | return 0 |
| 371 | fi |
||
| 372 | 1da30dfc | Thomas Schöpping | } |
| 373 | 69661903 | Thomas Schöpping | |
| 374 | 0a42f078 | Thomas Schöpping | ### delete project files ####################################################### |
| 375 | # Deletes all project files and optionally .user files, too. |
||
| 376 | # |
||
| 377 | # usage: deleteProjects [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe] |
||
| 378 | # arguments: -p, --path <path> |
||
| 379 | # Path where to delete the project files. |
||
| 380 | # -o, --out <var> |
||
| 381 | # Variable to store the path to. |
||
| 382 | # -w, --wipe |
||
| 383 | # Delete .user files as well. |
||
| 384 | 1da30dfc | Thomas Schöpping | # return: |
| 385 | # - 0: no error |
||
| 386 | # - 1: warning: function aborted by user |
||
| 387 | # - -1: error: unexpected user input |
||
| 388 | function deleteProjects {
|
||
| 389 | local projectdir="" |
||
| 390 | local outvar="" |
||
| 391 | local wipe=false |
||
| 392 | 69661903 | Thomas Schöpping | |
| 393 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 394 | local otherargs=() |
||
| 395 | while [ $# -gt 0 ]; do |
||
| 396 | if ( parseIsOption $1 ); then |
||
| 397 | case "$1" in |
||
| 398 | -p=*|--path=*) |
||
| 399 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 400 | -p|--path) |
||
| 401 | projectdir=$(realpath "$2"); shift 2;; |
||
| 402 | -o=*|--out=*) |
||
| 403 | outvar=${1#*=}; shift 1;;
|
||
| 404 | -o|--out) |
||
| 405 | outvar=$2; shift 2;; |
||
| 406 | -w|--wipe) |
||
| 407 | wipe=true; shift 1;; |
||
| 408 | *) |
||
| 409 | printError "invalid option: $1\n"; shift 1;; |
||
| 410 | esac |
||
| 411 | else |
||
| 412 | otherargs+=("$1")
|
||
| 413 | shift 1 |
||
| 414 | fi |
||
| 415 | 4cce70a8 | Thomas Schöpping | done |
| 416 | 69661903 | Thomas Schöpping | |
| 417 | 1da30dfc | Thomas Schöpping | # print message |
| 418 | if [ $wipe != true ]; then |
||
| 419 | printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n" |
||
| 420 | else |
||
| 421 | printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n" |
||
| 422 | fi |
||
| 423 | 69661903 | Thomas Schöpping | |
| 424 | 1da30dfc | Thomas Schöpping | # read project directory if required |
| 425 | if [ -z "$projectdir" ]; then |
||
| 426 | getProjectDir projectdir |
||
| 427 | fi |
||
| 428 | 69661903 | Thomas Schöpping | |
| 429 | 1da30dfc | Thomas Schöpping | # remove all project files |
| 430 | rm ${projectdir}/LightRing.includes 2>&1 | tee -a $LOG_FILE
|
||
| 431 | rm ${projectdir}/PowerManagement.includes 2>&1 | tee -a $LOG_FILE
|
||
| 432 | rm ${projectdir}/DiWheelDrive.includes 2>&1 | tee -a $LOG_FILE
|
||
| 433 | 69661903 | Thomas Schöpping | |
| 434 | 1da30dfc | Thomas Schöpping | rm ${projectdir}/LightRing.files 2>&1 | tee -a $LOG_FILE
|
| 435 | rm ${projectdir}/PowerManagement.files 2>&1 | tee -a $LOG_FILE
|
||
| 436 | rm ${projectdir}/DiWheelDrive.files 2>&1 | tee -a $LOG_FILE
|
||
| 437 | 4cce70a8 | Thomas Schöpping | |
| 438 | 1da30dfc | Thomas Schöpping | rm ${projectdir}/LightRing.config 2>&1 | tee -a $LOG_FILE
|
| 439 | rm ${projectdir}/PowerManagement.config 2>&1 | tee -a $LOG_FILE
|
||
| 440 | rm ${projectdir}/DiWheelDrive.config 2>&1 | tee -a $LOG_FILE
|
||
| 441 | 4cce70a8 | Thomas Schöpping | |
| 442 | 1da30dfc | Thomas Schöpping | rm ${projectdir}/LightRing.creator 2>&1 | tee -a $LOG_FILE
|
| 443 | rm ${projectdir}/PowerManagement.creator 2>&1 | tee -a $LOG_FILE
|
||
| 444 | rm ${projectdir}/DiWheelDrive.creator 2>&1 | tee -a $LOG_FILE
|
||
| 445 | 69661903 | Thomas Schöpping | |
| 446 | 1da30dfc | Thomas Schöpping | if [ $wipe == true ]; then |
| 447 | rm ${projectdir}/LightRing.user 2>&1 | tee -a $LOG_FILE
|
||
| 448 | rm ${projectdir}/PowerManagement.user 2>&1 | tee -a $LOG_FILE
|
||
| 449 | rm ${projectdir}/DiWheelDrive.user 2>&1 | tee -a $LOG_FILE
|
||
| 450 | fi |
||
| 451 | 69661903 | Thomas Schöpping | |
| 452 | 1da30dfc | Thomas Schöpping | # store the path to the output variable, if required |
| 453 | if [ ! -z "$outvar" ]; then |
||
| 454 | eval $outvar="$projectdir" |
||
| 455 | fi |
||
| 456 | 69661903 | Thomas Schöpping | |
| 457 | 1da30dfc | Thomas Schöpping | return 0 |
| 458 | } |
||
| 459 | 4cce70a8 | Thomas Schöpping | |
| 460 | 0a42f078 | Thomas Schöpping | ### create LightRing project files ############################################# |
| 461 | # Create project files for the LightRing module. |
||
| 462 | # |
||
| 463 | # usage: createLightRingProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
||
| 464 | # arguments: -p, --path <path> |
||
| 465 | # Path where to create the project files. |
||
| 466 | # --gcc=<path> |
||
| 467 | # Path to the GCC include directory. |
||
| 468 | # -o, --out <var> |
||
| 469 | # Variable to store the path to. |
||
| 470 | # --gccout=<var> |
||
| 471 | # Variable to store the path to the GCC include directory to. |
||
| 472 | # return: 0 |
||
| 473 | # No error or warning occurred. |
||
| 474 | # |
||
| 475 | 1da30dfc | Thomas Schöpping | function createLightRingProject {
|
| 476 | local projectdir="" |
||
| 477 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
| 478 | 1da30dfc | Thomas Schöpping | local outvar="" |
| 479 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
| 480 | 4cce70a8 | Thomas Schöpping | |
| 481 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 482 | local otherargs=() |
||
| 483 | while [ $# -gt 0 ]; do |
||
| 484 | if ( parseIsOption $1 ); then |
||
| 485 | case "$1" in |
||
| 486 | -p=*|--path=*) |
||
| 487 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 488 | -p|--path) |
||
| 489 | projectdir=$(realpath "$2"); shift 2;; |
||
| 490 | --gcc=*) |
||
| 491 | gccincludedir=$(realpath "${1#*=}"); shift 1;;
|
||
| 492 | --gcc) |
||
| 493 | gccincludedir=$(realpath "$2"); shift 2;; |
||
| 494 | -o=*|--out=*) |
||
| 495 | outvar=${1#*=}; shift 1;;
|
||
| 496 | -o|--out) |
||
| 497 | outvar=$2; shift 2;; |
||
| 498 | --gccout=*) |
||
| 499 | gccoutvar=$(realpath "${1#*=}"); shift 1;;
|
||
| 500 | --gccout) |
||
| 501 | gccoutvar=$(realpath "$2"); shift 2;; |
||
| 502 | *) |
||
| 503 | printError "invalid option: $1\n"; shift 1;; |
||
| 504 | esac |
||
| 505 | else |
||
| 506 | otherargs+=("$1")
|
||
| 507 | shift 1 |
||
| 508 | fi |
||
| 509 | 1da30dfc | Thomas Schöpping | done |
| 510 | |||
| 511 | # print message |
||
| 512 | 0a42f078 | Thomas Schöpping | printInfo "creating QtCreator project files for the LightRing module...\n" |
| 513 | 1da30dfc | Thomas Schöpping | |
| 514 | # read project directory if required |
||
| 515 | if [ -z "$projectdir" ]; then |
||
| 516 | getProjectDir projectdir |
||
| 517 | fi |
||
| 518 | |||
| 519 | # retrieve gcc-arm-none-eabi include dir |
||
| 520 | if [ -z "$gccincludedir" ]; then |
||
| 521 | 0a42f078 | Thomas Schöpping | retrieveGccIncludeDir gccincludedir |
| 522 | 1da30dfc | Thomas Schöpping | fi |
| 523 | |||
| 524 | # create project files |
||
| 525 | # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
||
| 526 | find $gccincludedir -type d > ${projectdir}/LightRing.includes
|
||
| 527 | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/LightRing.includes
|
||
| 528 | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_LightRing_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/LightRing.includes
|
||
| 529 | # generate a file that specifies all files |
||
| 530 | echo -n "" > ${projectdir}/LightRing.files
|
||
| 531 | for path in `cat ${projectdir}/LightRing.includes`; do
|
||
| 532 | find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/LightRing.files
|
||
| 533 | done |
||
| 534 | # generate a default project configuration file if none exists so far |
||
| 535 | if [ ! -f ${projectdir}/LightRing.config ]; then
|
||
| 536 | echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/LightRing.config
|
||
| 537 | echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/LightRing.config
|
||
| 538 | echo -e "" >> ${projectdir}/LightRing.config
|
||
| 539 | fi |
||
| 540 | # generate a default .creator file if none exists so far |
||
| 541 | if [ ! -f ${projectdir}/LightRing.creator ]; then
|
||
| 542 | echo -e "[general]" > ${projectdir}/LightRing.creator
|
||
| 543 | echo -e "" >> ${projectdir}/LightRing.creator
|
||
| 544 | fi |
||
| 545 | |||
| 546 | 0a42f078 | Thomas Schöpping | # fill the output variables |
| 547 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
| 548 | eval $outvar="$projectdir" |
||
| 549 | fi |
||
| 550 | 0a42f078 | Thomas Schöpping | if [ ! -z "$gccoutvar" ]; then |
| 551 | eval $gccoutvar="$gccincludedir" |
||
| 552 | fi |
||
| 553 | 4cce70a8 | Thomas Schöpping | |
| 554 | 1da30dfc | Thomas Schöpping | return 0 |
| 555 | } |
||
| 556 | 4cce70a8 | Thomas Schöpping | |
| 557 | 0a42f078 | Thomas Schöpping | ### create PowerManagement project files ####################################### |
| 558 | # Create project files for the PowerManagement module. |
||
| 559 | # |
||
| 560 | # usage: createPowerManagementProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
||
| 561 | # arguments: -p, --path <path> |
||
| 562 | # Path where to create the project files. |
||
| 563 | # --gcc=<path> |
||
| 564 | # Path to the GCC include directory. |
||
| 565 | # -o, --out <var> |
||
| 566 | # Variable to store the path to. |
||
| 567 | # --gccout=<var> |
||
| 568 | # Variable to store the path to the GCC include directory to. |
||
| 569 | # return: 0 |
||
| 570 | # No error or warning occurred. |
||
| 571 | # |
||
| 572 | 1da30dfc | Thomas Schöpping | function createPowerManagementProject {
|
| 573 | local projectdir="" |
||
| 574 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
| 575 | 1da30dfc | Thomas Schöpping | local outvar="" |
| 576 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
| 577 | 4cce70a8 | Thomas Schöpping | |
| 578 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 579 | local otherargs=() |
||
| 580 | while [ $# -gt 0 ]; do |
||
| 581 | if ( parseIsOption $1 ); then |
||
| 582 | case "$1" in |
||
| 583 | -p=*|--path=*) |
||
| 584 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 585 | -p|--path) |
||
| 586 | projectdir=$(realpath "$2"); shift 2;; |
||
| 587 | --gcc=*) |
||
| 588 | gccincludedir=$(realpath "${1#*=}"); shift 1;;
|
||
| 589 | --gcc) |
||
| 590 | gccincludedir=$(realpath "$2"); shift 2;; |
||
| 591 | -o=*|--out=*) |
||
| 592 | outvar=${1#*=}; shift 1;;
|
||
| 593 | -o|--out) |
||
| 594 | outvar=$2; shift 2;; |
||
| 595 | --gccout=*) |
||
| 596 | gccoutvar=$(realpath "${1#*=}"); shift 1;;
|
||
| 597 | --gccout) |
||
| 598 | gccoutvar=$(realpath "$2"); shift 2;; |
||
| 599 | *) |
||
| 600 | printError "invalid option: $1\n"; shift 1;; |
||
| 601 | esac |
||
| 602 | else |
||
| 603 | otherargs+=("$1")
|
||
| 604 | shift 1 |
||
| 605 | fi |
||
| 606 | 1da30dfc | Thomas Schöpping | done |
| 607 | |||
| 608 | # print message |
||
| 609 | 0a42f078 | Thomas Schöpping | printInfo "creating QtCreator project files for the PowerManagement module...\n" |
| 610 | 4cce70a8 | Thomas Schöpping | |
| 611 | 1da30dfc | Thomas Schöpping | # read project directory if required |
| 612 | if [ -z "$projectdir" ]; then |
||
| 613 | getProjectDir projectdir |
||
| 614 | fi |
||
| 615 | |||
| 616 | # retrieve gcc-arm-none-eabi include dir |
||
| 617 | if [ -z "$gccincludedir" ]; then |
||
| 618 | 0a42f078 | Thomas Schöpping | retrieveGccIncludeDir gccincludedir |
| 619 | 1da30dfc | Thomas Schöpping | fi |
| 620 | 4cce70a8 | Thomas Schöpping | |
| 621 | 1da30dfc | Thomas Schöpping | # create project files |
| 622 | # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
||
| 623 | find $gccincludedir -type d > ${projectdir}/PowerManagement.includes
|
||
| 624 | 0a42f078 | Thomas Schöpping | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/PowerManagement.includes
|
| 625 | 1da30dfc | Thomas Schöpping | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM4_STM32F405_Power_Management_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/PowerManagement.includes
|
| 626 | # generate a file that specifies all files |
||
| 627 | echo -n "" > ${projectdir}/PowerManagement.files
|
||
| 628 | for path in `cat ${projectdir}/PowerManagement.includes`; do
|
||
| 629 | find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/PowerManagement.files
|
||
| 630 | done |
||
| 631 | # generate a default project configuration file if none exists so far |
||
| 632 | if [ ! -f ${projectdir}/PowerManagement.config ]; then
|
||
| 633 | echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/PowerManagement.config
|
||
| 634 | echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/PowerManagement.config
|
||
| 635 | echo -e "" >> ${projectdir}/PowerManagement.config
|
||
| 636 | fi |
||
| 637 | # generate a default .creator file if none exists so far |
||
| 638 | if [ ! -f ${projectdir}/PowerManagement.creator ]; then
|
||
| 639 | echo -e "[general]" > ${projectdir}/PowerManagement.creator
|
||
| 640 | echo -e "" >> ${projectdir}/PowerManagement.creator
|
||
| 641 | fi |
||
| 642 | 4cce70a8 | Thomas Schöpping | |
| 643 | 0a42f078 | Thomas Schöpping | # fill the output variables |
| 644 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
| 645 | eval $outvar="$projectdir" |
||
| 646 | fi |
||
| 647 | 0a42f078 | Thomas Schöpping | if [ ! -z "$gccoutvar" ]; then |
| 648 | eval $gccoutvar="$gccincludedir" |
||
| 649 | fi |
||
| 650 | 4cce70a8 | Thomas Schöpping | |
| 651 | 1da30dfc | Thomas Schöpping | return 0 |
| 652 | } |
||
| 653 | 4cce70a8 | Thomas Schöpping | |
| 654 | 0a42f078 | Thomas Schöpping | ### create DiWheelDrive project files ########################################## |
| 655 | # Create project files for the DiWheelDrive module. |
||
| 656 | # |
||
| 657 | # usage: createDiWheelDriveProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
||
| 658 | # arguments: -p, --path <path> |
||
| 659 | # Path where to create the project files. |
||
| 660 | # --gcc=<path> |
||
| 661 | # Path to the GCC include directory. |
||
| 662 | # -o, --out <var> |
||
| 663 | # Variable to store the path to. |
||
| 664 | # --gccout=<var> |
||
| 665 | # Variable to store the path to the GCC include directory to. |
||
| 666 | # return: 0 |
||
| 667 | # No error or warning occurred. |
||
| 668 | # |
||
| 669 | 1da30dfc | Thomas Schöpping | function createDiWheelDriveProject {
|
| 670 | local projectdir="" |
||
| 671 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
| 672 | 1da30dfc | Thomas Schöpping | local outvar="" |
| 673 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
| 674 | 4cce70a8 | Thomas Schöpping | |
| 675 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 676 | local otherargs=() |
||
| 677 | while [ $# -gt 0 ]; do |
||
| 678 | if ( parseIsOption $1 ); then |
||
| 679 | case "$1" in |
||
| 680 | -p=*|--path=*) |
||
| 681 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 682 | -p|--path) |
||
| 683 | projectdir=$(realpath "$2"); shift 2;; |
||
| 684 | --gcc=*) |
||
| 685 | gccincludedir=$(realpath "${1#*=}"); shift 1;;
|
||
| 686 | --gcc) |
||
| 687 | gccincludedir=$(realpath "$2"); shift 2;; |
||
| 688 | -o=*|--out=*) |
||
| 689 | outvar=${1#*=}; shift 1;;
|
||
| 690 | -o|--out) |
||
| 691 | outvar=$2; shift 2;; |
||
| 692 | --gccout=*) |
||
| 693 | gccoutvar=$(realpath "${1#*=}"); shift 1;;
|
||
| 694 | --gccout) |
||
| 695 | gccoutvar=$(realpath "$2"); shift 2;; |
||
| 696 | *) |
||
| 697 | printError "invalid option: $1\n"; shift 1;; |
||
| 698 | esac |
||
| 699 | else |
||
| 700 | otherargs+=("$1")
|
||
| 701 | shift 1 |
||
| 702 | fi |
||
| 703 | 1da30dfc | Thomas Schöpping | done |
| 704 | 4cce70a8 | Thomas Schöpping | |
| 705 | 1da30dfc | Thomas Schöpping | # print message |
| 706 | 0a42f078 | Thomas Schöpping | printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
| 707 | 4cce70a8 | Thomas Schöpping | |
| 708 | 1da30dfc | Thomas Schöpping | # read project directory if required |
| 709 | if [ -z "$projectdir" ]; then |
||
| 710 | getProjectDir projectdir |
||
| 711 | fi |
||
| 712 | 4cce70a8 | Thomas Schöpping | |
| 713 | 1da30dfc | Thomas Schöpping | # retrieve gcc-arm-none-eabi include dir |
| 714 | if [ -z "$gccincludedir" ]; then |
||
| 715 | 0a42f078 | Thomas Schöpping | retrieveGccIncludeDir gccincludedir |
| 716 | 1da30dfc | Thomas Schöpping | fi |
| 717 | 4cce70a8 | Thomas Schöpping | |
| 718 | 1da30dfc | Thomas Schöpping | # create project files |
| 719 | # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
||
| 720 | find $gccincludedir -type d > ${projectdir}/DiWheelDrive.includes
|
||
| 721 | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/DiWheelDrive.includes
|
||
| 722 | find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_DiWheelDrive_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/DiWheelDrive.includes
|
||
| 723 | # generate a file that specifies all files |
||
| 724 | echo -n "" > ${projectdir}/DiWheelDrive.files
|
||
| 725 | for path in `cat ${projectdir}/DiWheelDrive.includes`; do
|
||
| 726 | find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/DiWheelDrive.files
|
||
| 727 | done |
||
| 728 | # generate a default project configuration file if none exists so far |
||
| 729 | if [ ! -f ${projectdir}/DiWheelDrive.config ]; then
|
||
| 730 | echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/DiWheelDrive.config
|
||
| 731 | echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/DiWheelDrive.config
|
||
| 732 | echo -e "" >> ${projectdir}/DiWheelDrive.config
|
||
| 733 | fi |
||
| 734 | # generate a default .creator file if none exists so far |
||
| 735 | if [ ! -f ${projectdir}/DiWheelDrive.creator ]; then
|
||
| 736 | echo -e "[general]" > ${projectdir}/DiWheelDrive.creator
|
||
| 737 | echo -e "" >> ${projectdir}/DiWheelDrive.creator
|
||
| 738 | fi |
||
| 739 | 4cce70a8 | Thomas Schöpping | |
| 740 | 0a42f078 | Thomas Schöpping | # fill the output variables |
| 741 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
| 742 | eval $outvar="$projectdir" |
||
| 743 | fi |
||
| 744 | 0a42f078 | Thomas Schöpping | if [ ! -z "$gccoutvar" ]; then |
| 745 | eval $gccoutvar="$gccincludedir" |
||
| 746 | fi |
||
| 747 | 4cce70a8 | Thomas Schöpping | |
| 748 | 1da30dfc | Thomas Schöpping | return 0 |
| 749 | } |
||
| 750 | 4cce70a8 | Thomas Schöpping | |
| 751 | 0a42f078 | Thomas Schöpping | ### create project files for al modules ######################################## |
| 752 | # Create project files for all modules. |
||
| 753 | # |
||
| 754 | # usage: createAllProjects |
||
| 755 | # arguments: n/a |
||
| 756 | # return: 0 |
||
| 757 | # No error or warning occurred. |
||
| 758 | # |
||
| 759 | 1da30dfc | Thomas Schöpping | function createAllProjects {
|
| 760 | 0a42f078 | Thomas Schöpping | # print message |
| 761 | printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
||
| 762 | 1da30dfc | Thomas Schöpping | |
| 763 | 0a42f078 | Thomas Schöpping | # read project directory |
| 764 | 1da30dfc | Thomas Schöpping | local projectdir="" |
| 765 | 0a42f078 | Thomas Schöpping | getProjectDir projectdir |
| 766 | printInfo "files will be created in $projectdir\n" |
||
| 767 | 4cce70a8 | Thomas Schöpping | |
| 768 | 0a42f078 | Thomas Schöpping | # retrieve gcc-arm-none-eabi include dir |
| 769 | retrieveGccIncludeDir gccincludedir |
||
| 770 | 4cce70a8 | Thomas Schöpping | |
| 771 | 1da30dfc | Thomas Schöpping | # create projects |
| 772 | 0a42f078 | Thomas Schöpping | createLightRingProject --path="$projectdir" --gcc="$gccincludedir" |
| 773 | createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir" |
||
| 774 | createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir" |
||
| 775 | 4cce70a8 | Thomas Schöpping | |
| 776 | 1da30dfc | Thomas Schöpping | return 0 |
| 777 | } |
||
| 778 | 4cce70a8 | Thomas Schöpping | |
| 779 | 0a42f078 | Thomas Schöpping | ### main function of this script ############################################### |
| 780 | # Creates, deletes and wipes QtCreator project files for the three AMiRo base modules. |
||
| 781 | # |
||
| 782 | # usage: see function printHelp |
||
| 783 | # arguments: see function printHelp |
||
| 784 | # return: 0 |
||
| 785 | # No error or warning ocurred. |
||
| 786 | # |
||
| 787 | 1da30dfc | Thomas Schöpping | function main {
|
| 788 | 0a42f078 | Thomas Schöpping | # print welcome/info text if not suppressed |
| 789 | 1da30dfc | Thomas Schöpping | if [[ $@ != *"--noinfo"* ]]; then |
| 790 | printWelcomeText |
||
| 791 | else |
||
| 792 | printf "######################################################################\n" |
||
| 793 | fi |
||
| 794 | printf "\n" |
||
| 795 | |||
| 796 | # set log file if specified |
||
| 797 | 0a42f078 | Thomas Schöpping | if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
| 798 | 1da30dfc | Thomas Schöpping | # get the parameter (file name) |
| 799 | local cmdidx=1 |
||
| 800 | 0a42f078 | Thomas Schöpping | while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do
|
| 801 | 1da30dfc | Thomas Schöpping | cmdidx=$[cmdidx + 1] |
| 802 | done |
||
| 803 | 0a42f078 | Thomas Schöpping | local cmd="${!cmdidx}"
|
| 804 | local logfile="" |
||
| 805 | if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
||
| 806 | logfile=${cmd#*=}
|
||
| 807 | else |
||
| 808 | local filenameidx=$((cmdidx + 1)) |
||
| 809 | logfile="${!filenameidx}"
|
||
| 810 | fi |
||
| 811 | 1da30dfc | Thomas Schöpping | # optionally force silent appending |
| 812 | 0a42f078 | Thomas Schöpping | if [[ "$cmd" = "--LOG"* ]]; then |
| 813 | setLogFile --option=a --quiet "$logfile" LOG_FILE |
||
| 814 | 1da30dfc | Thomas Schöpping | else |
| 815 | 0a42f078 | Thomas Schöpping | setLogFile "$logfile" LOG_FILE |
| 816 | 1da30dfc | Thomas Schöpping | printf "\n" |
| 817 | fi |
||
| 818 | fi |
||
| 819 | |||
| 820 | # log script name |
||
| 821 | printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
|
||
| 822 | 4cce70a8 | Thomas Schöpping | |
| 823 | 1da30dfc | Thomas Schöpping | # if --help or -h was specified, print the help text and exit |
| 824 | if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
||
| 825 | printHelp |
||
| 826 | printf "\n" |
||
| 827 | 7a91596e | Thomas Schöpping | quitScript |
| 828 | 1da30dfc | Thomas Schöpping | fi |
| 829 | |||
| 830 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 831 | local otherargs=() |
||
| 832 | while [ $# -gt 0 ]; do |
||
| 833 | if ( parseIsOption $1 ); then |
||
| 834 | case "$1" in |
||
| 835 | -h|--help) # already handled; ignore |
||
| 836 | shift 1;; |
||
| 837 | -c|--clean) |
||
| 838 | deleteProjects; printf "\n"; shift 1;; |
||
| 839 | -w|--wipe) |
||
| 840 | deleteProjects --wipe; printf "\n"; shift 1;; |
||
| 841 | --LightRing) |
||
| 842 | createLightRingProject; printf "\n"; shift 1;; |
||
| 843 | --PowerManagement) |
||
| 844 | createPowerManagementProject; printf "\n"; shift 1;; |
||
| 845 | --DiWheelDrive) |
||
| 846 | createDiWheelDriveProject; printf "\n"; shift 1;; |
||
| 847 | -a|--all) |
||
| 848 | createAllProjects; printf "\n"; shift 1;; |
||
| 849 | -q|--quit) |
||
| 850 | quitScript; shift 1;; |
||
| 851 | --log=*|--LOG=*) # already handled; ignore |
||
| 852 | shift 1;; |
||
| 853 | --log|--LOG) # already handled; ignore |
||
| 854 | shift 2;; |
||
| 855 | --noinfo) # already handled; ignore |
||
| 856 | shift 1;; |
||
| 857 | *) |
||
| 858 | printError "invalid option: $1\n"; shift 1;; |
||
| 859 | esac |
||
| 860 | else |
||
| 861 | otherargs+=("$1")
|
||
| 862 | shift 1 |
||
| 863 | fi |
||
| 864 | 1da30dfc | Thomas Schöpping | done |
| 865 | 4cce70a8 | Thomas Schöpping | |
| 866 | 0a42f078 | Thomas Schöpping | # interactive menu |
| 867 | while ( true ); do |
||
| 868 | 1da30dfc | Thomas Schöpping | # main menu info prompt and selection |
| 869 | printInfo "QtCreator setup main menu\n" |
||
| 870 | printf "Please select one of the following actions:\n" |
||
| 871 | printf " [C] - clean project files\n" |
||
| 872 | printf " [W] - wipe project and .user files\n" |
||
| 873 | printf " [L] - create a project for the LightRing module\n" |
||
| 874 | printf " [P] - create a project for the PowerManagement module\n" |
||
| 875 | printf " [D] - create a project for the DiWheelDrive module\n" |
||
| 876 | printf " [A] - create a project for all modules\n" |
||
| 877 | printf " [Q] - quit this setup\n" |
||
| 878 | 0a42f078 | Thomas Schöpping | local userinput="" |
| 879 | readUserInput "CcWwLlPpDdAaQq" userinput |
||
| 880 | 1da30dfc | Thomas Schöpping | printf "\n" |
| 881 | |||
| 882 | # evaluate user selection |
||
| 883 | 0a42f078 | Thomas Schöpping | case "$userinput" in |
| 884 | 1da30dfc | Thomas Schöpping | C|c) |
| 885 | 0a42f078 | Thomas Schöpping | deleteProjects; printf "\n";; |
| 886 | 1da30dfc | Thomas Schöpping | W|w) |
| 887 | 0a42f078 | Thomas Schöpping | deleteProjects --wipe; printf "\n";; |
| 888 | 1da30dfc | Thomas Schöpping | L|l) |
| 889 | 0a42f078 | Thomas Schöpping | createLightRingProject; printf "\n";; |
| 890 | 1da30dfc | Thomas Schöpping | P|p) |
| 891 | 0a42f078 | Thomas Schöpping | createPowerManagementProject; printf "\n";; |
| 892 | 1da30dfc | Thomas Schöpping | D|d) |
| 893 | 0a42f078 | Thomas Schöpping | createDiWheelDriveProject; printf "\n";; |
| 894 | 1da30dfc | Thomas Schöpping | A|a) |
| 895 | 0a42f078 | Thomas Schöpping | createAllProjects; printf "\n";; |
| 896 | 1da30dfc | Thomas Schöpping | Q|q) |
| 897 | 0a42f078 | Thomas Schöpping | quitScript;; |
| 898 | 1da30dfc | Thomas Schöpping | *) # sanity check (exit with error) |
| 899 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $userinput\n";; |
| 900 | 4cce70a8 | Thomas Schöpping | esac |
| 901 | done |
||
| 902 | 1da30dfc | Thomas Schöpping | |
| 903 | exit 0 |
||
| 904 | } |
||
| 905 | 69661903 | Thomas Schöpping | |
| 906 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 907 | 1da30dfc | Thomas Schöpping | # SCRIPT ENTRY POINT # |
| 908 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 909 | 69661903 | Thomas Schöpping | |
| 910 | 1da30dfc | Thomas Schöpping | main "$@" |