Statistics
| Branch: | Tag: | Revision:

amiro-blt / tools / ide / QtCreator / QtCreatorSetup.sh @ f7d2c786

History | View | Annotate | Download (33.127 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 449d916a Thomas Schöpping
# Copyright (C) 2016..2019  Thomas Schöpping et al.                            #
5 4cce70a8 Thomas Schöpping
#                                                                              #
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 0dc9f2f9 Thomas Schöpping
#                 Possible values are 'a', 'c', 'r' and 'n'.
173
#                 - a: append (starts with a separator)
174
#                 - c: continue (does not insert a seperator)
175 0a42f078 Thomas Schöpping
#                 - r: delete and restart
176
#                 - n: no log
177
#                 If no option is secified but <file> exists, an interactive selection is provided.
178
#             --quiet
179
#                 Suppress all messages.
180
#             <infile>
181
#                 Path of the wanted log file.
182
#             <outvar>
183
#                 Variable to store the path of the log file to.
184
# return:     0
185
#                 No error or warning occurred.
186
#             -1
187
#                 Error: invalid input
188
#
189
function setLogFile {
190
  local filepath=""
191 1da30dfc Thomas Schöpping
  local option=""
192 0a42f078 Thomas Schöpping
  local quiet=false
193
194
  # parse arguments
195
  local otherargs=()
196
  while [ $# -gt 0 ]; do
197
    if ( parseIsOption $1 ); then
198
      case "$1" in
199
        -o=*|--option=*)
200
          option=${1#*=}; shift 1;;
201
        -o*|--option*)
202
          option="$2"; shift 2;;
203
        -q|--quiet)
204
          quiet=true; shift 1;;
205
        *)
206
          printError "invalid option: $1\n"; shift 1;;
207
      esac
208
    else
209
      otherargs+=("$1")
210
      shift 1
211
    fi
212 1da30dfc Thomas Schöpping
  done
213 0a42f078 Thomas Schöpping
  filepath=$(realpath ${otherargs[0]})
214 69661903 Thomas Schöpping
215 1da30dfc Thomas Schöpping
  # if file already exists
216 0a42f078 Thomas Schöpping
  if [ -e $filepath ]; then
217 1da30dfc Thomas Schöpping
    # if no option was specified, ask what to do
218 0a42f078 Thomas Schöpping
    if [ -z "$option" ]; then
219
      printWarning "log file $filepath already esists\n"
220
      local userinput=""
221
      printf "Select what to do:\n"
222 1da30dfc Thomas Schöpping
      printf "  [A] - append log\n"
223
      printf "  [R] - restart log (delete existing file)\n"
224
      printf "  [N] - no log\n"
225 0a42f078 Thomas Schöpping
      readUserInput "AaRrNn" userinput
226 1da30dfc Thomas Schöpping
      option=${userinput,,}
227
    fi
228
    # evaluate option
229 0a42f078 Thomas Schöpping
    case "$option" in
230 0dc9f2f9 Thomas Schöpping
      a|c)
231 0a42f078 Thomas Schöpping
        if [ $quiet = false ]; then
232
          printInfo "appending log to $filepath\n"
233
        fi
234 0dc9f2f9 Thomas Schöpping
        if [ $option != c ]; then
235
          printf "\n" >> $filepath
236
          printf "######################################################################\n" >> $filepath
237
          printf "\n" >> $filepath
238
        fi
239 1da30dfc Thomas Schöpping
        ;;
240
      r)
241 0a42f078 Thomas Schöpping
        echo -n "" > $filepath
242
        if [ $quiet = false ]; then
243
          printInfo "content of $filepath wiped\n"
244
        fi
245 1da30dfc Thomas Schöpping
        ;;
246
      n)
247 0a42f078 Thomas Schöpping
        if [ $quiet = false ]; then
248
          printInfo "no log file will be generated\n"
249
        fi
250
        filepath=""
251 1da30dfc Thomas Schöpping
        ;;
252
      *) # sanity check (return error)
253 0a42f078 Thomas Schöpping
        printError "unexpected argument: $option\n"; return -1;;
254 1da30dfc Thomas Schöpping
    esac
255 69661903 Thomas Schöpping
  else
256 0a42f078 Thomas Schöpping
    if [ $quiet = false ]; then
257
      printInfo "log file set to $filepath\n"
258
    fi
259 69661903 Thomas Schöpping
  fi
260 0a42f078 Thomas Schöpping
261
  eval ${otherargs[1]}="$filepath"
262
263
  return 0
264 69661903 Thomas Schöpping
}
265 4cce70a8 Thomas Schöpping
266 fad4c1e7 Thomas Schöpping
### check whether commands are available #######################################
267
# Checks whether the specified commands are available and can be executed.
268
#
269
# usage:      checkCommand [<command> <command> ...]
270
# arguments:  <command>
271
#                 Name of the command to check.
272
# return:     0
273
#                 All requested commands are available.
274
#             >0
275
#                 Number of requested commands that were not found.
276
#             -1
277
#                 No argument given.
278
#
279
function checkCommands {
280
  local status=0
281
282
  # return if no argument was specified
283
  if [ $# -eq 0 ]; then
284
    return -1
285
  fi
286
287
  # check all specified commands
288
  while [ $# -gt 0 ]; do
289
    command -v $1 &>/dev/null
290
    if [ $? -ne 0 ]; then
291
      printWarning "Command '$1' not available.\n"
292
      status=$((status + 1))
293
    fi
294
    shift 1
295
  done
296
297
  return $status
298
}
299
300 1da30dfc Thomas Schöpping
################################################################################
301
# SPECIFIC FUNCTIONS                                                           #
302
################################################################################
303
304 0a42f078 Thomas Schöpping
### print welcome text #########################################################
305
# Prints a welcome message to standard out.
306
#
307
# usage:      printWelcomeText
308
# arguments:  n/a
309
# return:     n/a
310
#
311 1da30dfc Thomas Schöpping
function printWelcomeText {
312 4cce70a8 Thomas Schöpping
  printf "######################################################################\n"
313
  printf "#                                                                    #\n"
314 1da30dfc Thomas Schöpping
  printf "#                  Welcome to the QtCreator setup!                   #\n"
315 4cce70a8 Thomas Schöpping
  printf "#                                                                    #\n"
316
  printf "######################################################################\n"
317
  printf "#                                                                    #\n"
318 449d916a Thomas Schöpping
  printf "# Copyright (c) 2016..2019  Thomas Schöpping                         #\n"
319 4cce70a8 Thomas Schöpping
  printf "#                                                                    #\n"
320
  printf "# This is free software; see the source for copying conditions.      #\n"
321
  printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n"
322
  printf "# A PARTICULAR PURPOSE. The development of this software was         #\n"
323
  printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction  #\n"
324
  printf "# Technology. The Excellence Cluster EXC 227 is a grant of the       #\n"
325
  printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n"
326
  printf "# Excellence Initiative.                                             #\n"
327
  printf "#                                                                    #\n"
328
  printf "######################################################################\n"
329 1da30dfc Thomas Schöpping
}
330
331 0a42f078 Thomas Schöpping
### print help #################################################################
332
# Prints a help text to standard out.
333
#
334
# usage:      printHelp
335
# arguments:  n/a
336
# return:     n/a
337
#
338 1da30dfc Thomas Schöpping
function printHelp {
339
  printInfo "printing help text\n"
340 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"
341
  printf "\n"
342
  printf "options:  -h, --help\n"
343
  printf "              Print this help text.\n"
344
  printf "          -c, --clean\n"
345
  printf "              Delete project files.\n"
346
  printf "          -w, --wipe\n"
347
  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
  printf "          -q, --quit\n"
357
  printf "              Quit the script.\n"
358
  printf "          --log=<file>\n"
359
  printf "              Specify a log file.\n"
360 1da30dfc Thomas Schöpping
}
361 69661903 Thomas Schöpping
362 0a42f078 Thomas Schöpping
### read directory where to create/delete projects #############################
363
# Read the directory where to create/delete project files from user.
364
#
365
# usage:      getProjectDir <pathvar>
366
# arguments:  <pathvar>
367
#                 Variable to store the selected path to.
368
# return:     n/a
369
#
370 1da30dfc Thomas Schöpping
function getProjectDir {
371 0a42f078 Thomas Schöpping
  printLog "reading path for project files from user...\n"
372 9085c3a0 Thomas Schöpping
  local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/)
373 0a42f078 Thomas Schöpping
  local input=""
374
  read -p "Path where to create/delete project files: " -i $amirobltdir -e input
375
  printLog "user selected path $(realpath $input)\n"
376
  eval $1="$(realpath $input)"
377 1da30dfc Thomas Schöpping
}
378 69661903 Thomas Schöpping
379 0a42f078 Thomas Schöpping
### retrieves the ARM-NONE-EABI-GCC include directory ##########################
380
# Retrieves the include directory of the currently set arm-none-eabi-gcc.
381
#
382
# usage:      retrieveGccIncludeDir <path>
383
# arguments:  <path>
384
#                 Variable to store the path to.
385
# return:    0
386
#                 No error or warning occurred.
387
#            -1
388
#                 Error: Command 'arm-none-eabi-gcc' not found.
389
#
390 1da30dfc Thomas Schöpping
function retrieveGccIncludeDir {
391
  # retrieve binary path or link
392 0a42f078 Thomas Schöpping
  local binpath=$(which arm-none-eabi-gcc)
393 1da30dfc Thomas Schöpping
  if [ -z "$binpath" ]; then
394 0a42f078 Thomas Schöpping
    printError "command 'arm-none-eabi-gcc' not found\n"
395 1da30dfc Thomas Schöpping
    return -1
396 0a42f078 Thomas Schöpping
  else 
397 69661903 Thomas Schöpping
398 0a42f078 Thomas Schöpping
    # traverse any links
399
    while [ -L "$binpath" ]; do
400 7737db33 Thomas Schöpping
      binpath=$(realpath $(dirname $binpath)/$(readlink $binpath))
401 0a42f078 Thomas Schöpping
    done
402
    printInfo "gcc-arm-none-eabi detected: $binpath\n"
403 69661903 Thomas Schöpping
404 0a42f078 Thomas Schöpping
    # return include path
405
    eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
406 69661903 Thomas Schöpping
407 0a42f078 Thomas Schöpping
    return 0
408
  fi
409 1da30dfc Thomas Schöpping
}
410 69661903 Thomas Schöpping
411 0a42f078 Thomas Schöpping
### delete project files #######################################################
412
# Deletes all project files and optionally .user files, too.
413
#
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 1da30dfc Thomas Schöpping
# 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
429 69661903 Thomas Schöpping
430 0a42f078 Thomas Schöpping
  # 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
452 4cce70a8 Thomas Schöpping
  done
453 69661903 Thomas Schöpping
454 1da30dfc Thomas Schöpping
  # 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 69661903 Thomas Schöpping
461 1da30dfc Thomas Schöpping
  # read project directory if required
462
  if [ -z "$projectdir" ]; then
463
    getProjectDir projectdir
464
  fi
465 69661903 Thomas Schöpping
466 1da30dfc Thomas Schöpping
  # 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 69661903 Thomas Schöpping
471 1da30dfc Thomas Schöpping
  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 4cce70a8 Thomas Schöpping
475 1da30dfc Thomas Schöpping
  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 4cce70a8 Thomas Schöpping
479 1da30dfc Thomas Schöpping
  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 69661903 Thomas Schöpping
483 1da30dfc Thomas Schöpping
  if [ $wipe == true ]; then
484 a8ddce31 Thomas Schöpping
    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 1da30dfc Thomas Schöpping
  fi
488 69661903 Thomas Schöpping
489 1da30dfc Thomas Schöpping
  # store the path to the output variable, if required
490
  if [ ! -z "$outvar" ]; then
491
    eval $outvar="$projectdir"
492
  fi
493 69661903 Thomas Schöpping
494 1da30dfc Thomas Schöpping
  return 0
495
}
496 4cce70a8 Thomas Schöpping
497 0a42f078 Thomas Schöpping
### create LightRing project files #############################################
498
# Create project files for the LightRing module.
499
#
500
# usage:      createLightRingProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
501
# arguments:  -p, --path <path>
502
#                 Path where to create the project files.
503
#             --gcc=<path>
504
#                 Path to the GCC include directory.
505
#             -o, --out <var>
506
#                 Variable to store the path to.
507
#             --gccout=<var>
508
#                 Variable to store the path to the GCC include directory to.
509
# return:     0
510
#                 No error or warning occurred.
511
#
512 1da30dfc Thomas Schöpping
function createLightRingProject {
513 cc06d380 Thomas Schöpping
  local userdir=$(pwd)
514 1da30dfc Thomas Schöpping
  local projectdir=""
515 0a42f078 Thomas Schöpping
  local gccincludedir=""
516 1da30dfc Thomas Schöpping
  local outvar=""
517 0a42f078 Thomas Schöpping
  local gccoutvar=""
518 4cce70a8 Thomas Schöpping
519 0a42f078 Thomas Schöpping
  # parse arguments
520
  local otherargs=()
521
  while [ $# -gt 0 ]; do
522
    if ( parseIsOption $1 ); then
523
      case "$1" in
524
        -p=*|--path=*)
525
          projectdir=$(realpath "${1#*=}"); shift 1;;
526
        -p|--path)
527
          projectdir=$(realpath "$2"); shift 2;;
528
        --gcc=*)
529
          gccincludedir=$(realpath "${1#*=}"); shift 1;;
530
        --gcc)
531
          gccincludedir=$(realpath "$2"); shift 2;;
532
        -o=*|--out=*)
533
          outvar=${1#*=}; shift 1;;
534
        -o|--out)
535
          outvar=$2; shift 2;;
536
        --gccout=*)
537
          gccoutvar=$(realpath "${1#*=}"); shift 1;;
538
        --gccout)
539
          gccoutvar=$(realpath "$2"); shift 2;;
540
        *)
541
          printError "invalid option: $1\n"; shift 1;;
542
      esac
543
    else
544
      otherargs+=("$1")
545
      shift 1
546
    fi
547 1da30dfc Thomas Schöpping
  done
548
549
  # print message
550 0a42f078 Thomas Schöpping
  printInfo "creating QtCreator project files for the LightRing module...\n"
551 1da30dfc Thomas Schöpping
552 cc06d380 Thomas Schöpping
  # read absolute project directory if required
553 1da30dfc Thomas Schöpping
  if [ -z "$projectdir" ]; then
554
    getProjectDir projectdir
555
  fi
556
557 cc06d380 Thomas Schöpping
  # retrieve absolute GCC include dir
558 1da30dfc Thomas Schöpping
  if [ -z "$gccincludedir" ]; then
559 0a42f078 Thomas Schöpping
    retrieveGccIncludeDir gccincludedir
560 1da30dfc Thomas Schöpping
  fi
561
562 cc06d380 Thomas Schöpping
  # move to project directory
563
  cd $projectdir
564
565 1da30dfc Thomas Schöpping
  # 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 9085c3a0 Thomas Schöpping
  find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Source) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/LightRing.includes
569 5cff2671 Thomas Schöpping
  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 1da30dfc Thomas Schöpping
  # 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
574
  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
580
  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
585
  fi
586
587 cc06d380 Thomas Schöpping
  # go back to user directory
588
  cd $userdir
589
590 0a42f078 Thomas Schöpping
  # fill the output variables
591 1da30dfc Thomas Schöpping
  if [ ! -z "$outvar" ]; then
592
    eval $outvar="$projectdir"
593
  fi
594 0a42f078 Thomas Schöpping
  if [ ! -z "$gccoutvar" ]; then
595
    eval $gccoutvar="$gccincludedir"
596
  fi
597 4cce70a8 Thomas Schöpping
598 1da30dfc Thomas Schöpping
  return 0
599
}
600 4cce70a8 Thomas Schöpping
601 0a42f078 Thomas Schöpping
### create PowerManagement project files #######################################
602
# Create project files for the PowerManagement module.
603
#
604
# usage:      createPowerManagementProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
605
# arguments:  -p, --path <path>
606
#                 Path where to create the project files.
607
#             --gcc=<path>
608
#                 Path to the GCC include directory.
609
#             -o, --out <var>
610
#                 Variable to store the path to.
611
#             --gccout=<var>
612
#                 Variable to store the path to the GCC include directory to.
613
# return:     0
614
#                 No error or warning occurred.
615
#
616 1da30dfc Thomas Schöpping
function createPowerManagementProject {
617 cc06d380 Thomas Schöpping
  local userdir=$(pwd)
618 1da30dfc Thomas Schöpping
  local projectdir=""
619 0a42f078 Thomas Schöpping
  local gccincludedir=""
620 1da30dfc Thomas Schöpping
  local outvar=""
621 0a42f078 Thomas Schöpping
  local gccoutvar=""
622 4cce70a8 Thomas Schöpping
623 0a42f078 Thomas Schöpping
  # parse arguments
624
  local otherargs=()
625
  while [ $# -gt 0 ]; do
626
    if ( parseIsOption $1 ); then
627
      case "$1" in
628
        -p=*|--path=*)
629
          projectdir=$(realpath "${1#*=}"); shift 1;;
630
        -p|--path)
631
          projectdir=$(realpath "$2"); shift 2;;
632
        --gcc=*)
633
          gccincludedir=$(realpath "${1#*=}"); shift 1;;
634
        --gcc)
635
          gccincludedir=$(realpath "$2"); shift 2;;
636
        -o=*|--out=*)
637
          outvar=${1#*=}; shift 1;;
638
        -o|--out)
639
          outvar=$2; shift 2;;
640
        --gccout=*)
641
          gccoutvar=$(realpath "${1#*=}"); shift 1;;
642
        --gccout)
643
          gccoutvar=$(realpath "$2"); shift 2;;
644
        *)
645
          printError "invalid option: $1\n"; shift 1;;
646
      esac
647
    else
648
      otherargs+=("$1")
649
      shift 1
650
    fi
651 1da30dfc Thomas Schöpping
  done
652
653
  # print message
654 0a42f078 Thomas Schöpping
  printInfo "creating QtCreator project files for the PowerManagement module...\n"
655 4cce70a8 Thomas Schöpping
656 cc06d380 Thomas Schöpping
  # read absolute project directory if required
657 1da30dfc Thomas Schöpping
  if [ -z "$projectdir" ]; then
658
    getProjectDir projectdir
659
  fi
660
661 cc06d380 Thomas Schöpping
  # retrieve absolute GCC include dir
662 1da30dfc Thomas Schöpping
  if [ -z "$gccincludedir" ]; then
663 0a42f078 Thomas Schöpping
    retrieveGccIncludeDir gccincludedir
664 1da30dfc Thomas Schöpping
  fi
665 4cce70a8 Thomas Schöpping
666 cc06d380 Thomas Schöpping
  # move to project directory
667
  cd $projectdir
668
669 1da30dfc Thomas Schöpping
  # 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 df2f435c Thomas Schöpping
  find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Source) -type d | grep -v "ARMCM3_STM32" >> ${projectdir}/PowerManagement.includes
673 5cff2671 Thomas Schöpping
  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 1da30dfc Thomas Schöpping
  # 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
678
  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
689
  fi
690 4cce70a8 Thomas Schöpping
691 cc06d380 Thomas Schöpping
  # go back to user directory
692
  cd $userdir
693
694
695 0a42f078 Thomas Schöpping
  # fill the output variables
696 1da30dfc Thomas Schöpping
  if [ ! -z "$outvar" ]; then
697
    eval $outvar="$projectdir"
698
  fi
699 0a42f078 Thomas Schöpping
  if [ ! -z "$gccoutvar" ]; then
700
    eval $gccoutvar="$gccincludedir"
701
  fi
702 4cce70a8 Thomas Schöpping
703 1da30dfc Thomas Schöpping
  return 0
704
}
705 4cce70a8 Thomas Schöpping
706 0a42f078 Thomas Schöpping
### create DiWheelDrive project files ##########################################
707
# Create project files for the DiWheelDrive module.
708
#
709
# usage:      createDiWheelDriveProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
710
# arguments:  -p, --path <path>
711
#                 Path where to create the project files.
712
#             --gcc=<path>
713
#                 Path to the GCC include directory.
714
#             -o, --out <var>
715
#                 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.
720
#
721 1da30dfc Thomas Schöpping
function createDiWheelDriveProject {
722 cc06d380 Thomas Schöpping
  local userdir=$(pwd)
723 1da30dfc Thomas Schöpping
  local projectdir=""
724 0a42f078 Thomas Schöpping
  local gccincludedir=""
725 1da30dfc Thomas Schöpping
  local outvar=""
726 0a42f078 Thomas Schöpping
  local gccoutvar=""
727 4cce70a8 Thomas Schöpping
728 0a42f078 Thomas Schöpping
  # parse arguments
729
  local otherargs=()
730
  while [ $# -gt 0 ]; do
731
    if ( parseIsOption $1 ); then
732
      case "$1" in
733
        -p=*|--path=*)
734
          projectdir=$(realpath "${1#*=}"); shift 1;;
735
        -p|--path)
736
          projectdir=$(realpath "$2"); shift 2;;
737
        --gcc=*)
738
          gccincludedir=$(realpath "${1#*=}"); shift 1;;
739
        --gcc)
740
          gccincludedir=$(realpath "$2"); shift 2;;
741
        -o=*|--out=*)
742
          outvar=${1#*=}; shift 1;;
743
        -o|--out)
744
          outvar=$2; shift 2;;
745
        --gccout=*)
746
          gccoutvar=$(realpath "${1#*=}"); shift 1;;
747
        --gccout)
748
          gccoutvar=$(realpath "$2"); shift 2;;
749
        *)
750
          printError "invalid option: $1\n"; shift 1;;
751
      esac
752
    else
753
      otherargs+=("$1")
754
      shift 1
755
    fi
756 1da30dfc Thomas Schöpping
  done
757 4cce70a8 Thomas Schöpping
758 1da30dfc Thomas Schöpping
  # print message
759 0a42f078 Thomas Schöpping
  printInfo "creating QtCreator project files for the DiWheelDrive module...\n"
760 4cce70a8 Thomas Schöpping
761 cc06d380 Thomas Schöpping
  # read absolute project directory if required
762 1da30dfc Thomas Schöpping
  if [ -z "$projectdir" ]; then
763
    getProjectDir projectdir
764
  fi
765 4cce70a8 Thomas Schöpping
766 cc06d380 Thomas Schöpping
  # retrieve absolute GCC include dir
767 1da30dfc Thomas Schöpping
  if [ -z "$gccincludedir" ]; then
768 0a42f078 Thomas Schöpping
    retrieveGccIncludeDir gccincludedir
769 1da30dfc Thomas Schöpping
  fi
770 4cce70a8 Thomas Schöpping
771 cc06d380 Thomas Schöpping
  # move to project directory
772
  cd $projectdir
773
774
775 1da30dfc Thomas Schöpping
  # 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 9085c3a0 Thomas Schöpping
  find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Source) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/DiWheelDrive.includes
779 5cff2671 Thomas Schöpping
  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 1da30dfc Thomas Schöpping
  # 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
790
  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
795
  fi
796 4cce70a8 Thomas Schöpping
797 cc06d380 Thomas Schöpping
  # go back to user directory
798
  cd $userdir
799
800
801 0a42f078 Thomas Schöpping
  # fill the output variables
802 1da30dfc Thomas Schöpping
  if [ ! -z "$outvar" ]; then
803
    eval $outvar="$projectdir"
804
  fi
805 0a42f078 Thomas Schöpping
  if [ ! -z "$gccoutvar" ]; then
806
    eval $gccoutvar="$gccincludedir"
807
  fi
808 4cce70a8 Thomas Schöpping
809 1da30dfc Thomas Schöpping
  return 0
810
}
811 4cce70a8 Thomas Schöpping
812 0a42f078 Thomas Schöpping
### 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 1da30dfc Thomas Schöpping
function createAllProjects {
821 0a42f078 Thomas Schöpping
  # print message
822
  printInfo "creating QtCreator project files for the DiWheelDrive module...\n"
823 1da30dfc Thomas Schöpping
824 0a42f078 Thomas Schöpping
  # read project directory
825 1da30dfc Thomas Schöpping
  local projectdir=""
826 0a42f078 Thomas Schöpping
  getProjectDir projectdir
827
  printInfo "files will be created in $projectdir\n"
828 4cce70a8 Thomas Schöpping
829 0a42f078 Thomas Schöpping
  # retrieve gcc-arm-none-eabi include dir
830
  retrieveGccIncludeDir gccincludedir
831 4cce70a8 Thomas Schöpping
832 1da30dfc Thomas Schöpping
  # create projects
833 0a42f078 Thomas Schöpping
  createLightRingProject --path="$projectdir" --gcc="$gccincludedir"
834
  createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir"
835
  createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir"
836 4cce70a8 Thomas Schöpping
837 1da30dfc Thomas Schöpping
  return 0
838
}
839 4cce70a8 Thomas Schöpping
840 0a42f078 Thomas Schöpping
### main function of this script ###############################################
841
# Creates, deletes and wipes QtCreator project files for the three AMiRo base modules.
842
#
843
# usage:      see function printHelp
844
# arguments:  see function printHelp
845
# return:     0
846
#                 No error or warning ocurred.
847
#
848 1da30dfc Thomas Schöpping
function main {
849 0a42f078 Thomas Schöpping
# print welcome/info text if not suppressed
850 1da30dfc Thomas Schöpping
  if [[ $@ != *"--noinfo"* ]]; then
851
    printWelcomeText
852
  else
853
    printf "######################################################################\n"
854
  fi
855
  printf "\n"
856
857 1446566f Thomas Schöpping
  # if --help or -h was specified, print the help text and exit
858
  if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then
859
    printHelp
860
    printf "\n"
861
    quitScript
862
  fi
863
864 1da30dfc Thomas Schöpping
  # set log file if specified
865 0a42f078 Thomas Schöpping
  if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then
866 1da30dfc Thomas Schöpping
    # get the parameter (file name)
867
    local cmdidx=1
868 0a42f078 Thomas Schöpping
    while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do
869 1da30dfc Thomas Schöpping
      cmdidx=$[cmdidx + 1]
870
    done
871 0a42f078 Thomas Schöpping
    local cmd="${!cmdidx}"
872
    local logfile=""
873
    if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then
874
      logfile=${cmd#*=}
875
    else
876
      local filenameidx=$((cmdidx + 1))
877
      logfile="${!filenameidx}"
878
    fi
879 1da30dfc Thomas Schöpping
    # optionally force silent appending
880 0a42f078 Thomas Schöpping
    if [[ "$cmd" = "--LOG"* ]]; then
881 0dc9f2f9 Thomas Schöpping
      setLogFile --option=c --quiet "$logfile" LOG_FILE
882 1da30dfc Thomas Schöpping
    else
883 0a42f078 Thomas Schöpping
      setLogFile "$logfile" LOG_FILE
884 1da30dfc Thomas Schöpping
      printf "\n"
885
    fi
886
  fi
887
  # log script name
888
  printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
889 4cce70a8 Thomas Schöpping
890 0a42f078 Thomas Schöpping
  # parse arguments
891
  local otherargs=()
892
  while [ $# -gt 0 ]; do
893
    if ( parseIsOption $1 ); then
894
      case "$1" in
895
        -h|--help) # already handled; ignore
896
          shift 1;;
897
        -c|--clean)
898
          deleteProjects; printf "\n"; shift 1;;
899
        -w|--wipe)
900
          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
        -q|--quit)
910
          quitScript; shift 1;;
911
        --log=*|--LOG=*) # already handled; ignore
912
          shift 1;;
913
        --log|--LOG) # already handled; ignore
914
          shift 2;;
915
        --noinfo) # already handled; ignore
916
          shift 1;;
917
        *)
918
          printError "invalid option: $1\n"; shift 1;;
919
      esac
920
    else
921
      otherargs+=("$1")
922
      shift 1
923
    fi
924 1da30dfc Thomas Schöpping
  done
925 4cce70a8 Thomas Schöpping
926 0a42f078 Thomas Schöpping
# interactive menu
927
  while ( true ); do
928 1da30dfc Thomas Schöpping
    # main menu info prompt and selection
929
    printInfo "QtCreator setup main menu\n"
930
    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"
936
    printf "  [A] - create a project for all modules\n"
937
    printf "  [Q] - quit this setup\n"
938 0a42f078 Thomas Schöpping
    local userinput=""
939
    readUserInput "CcWwLlPpDdAaQq" userinput
940 1da30dfc Thomas Schöpping
    printf "\n"
941
942
    # evaluate user selection
943 0a42f078 Thomas Schöpping
    case "$userinput" in
944 1da30dfc Thomas Schöpping
      C|c)
945 0a42f078 Thomas Schöpping
        deleteProjects; printf "\n";;
946 1da30dfc Thomas Schöpping
      W|w)
947 0a42f078 Thomas Schöpping
        deleteProjects --wipe; printf "\n";;
948 1da30dfc Thomas Schöpping
      L|l)
949 0a42f078 Thomas Schöpping
        createLightRingProject; printf "\n";;
950 1da30dfc Thomas Schöpping
      P|p)
951 0a42f078 Thomas Schöpping
        createPowerManagementProject; printf "\n";;
952 1da30dfc Thomas Schöpping
      D|d)
953 0a42f078 Thomas Schöpping
        createDiWheelDriveProject; printf "\n";;
954 1da30dfc Thomas Schöpping
      A|a)
955 0a42f078 Thomas Schöpping
        createAllProjects; printf "\n";;
956 1da30dfc Thomas Schöpping
      Q|q)
957 0a42f078 Thomas Schöpping
        quitScript;;
958 1da30dfc Thomas Schöpping
      *) # sanity check (exit with error)
959 0a42f078 Thomas Schöpping
        printError "unexpected argument: $userinput\n";;
960 4cce70a8 Thomas Schöpping
    esac
961
  done
962 1da30dfc Thomas Schöpping
963
  exit 0
964
}
965 69661903 Thomas Schöpping
966 4cce70a8 Thomas Schöpping
################################################################################
967 1da30dfc Thomas Schöpping
# SCRIPT ENTRY POINT                                                           #
968 4cce70a8 Thomas Schöpping
################################################################################
969 69661903 Thomas Schöpping
970 1da30dfc Thomas Schöpping
main "$@"