Revision 0a42f078 ide/QtCreator/QtCreatorSetup.sh

View differences:

ide/QtCreator/QtCreatorSetup.sh
27 27
# GENERIC FUNCTIONS                                                            #
28 28
################################################################################
29 29

  
30
### print an error
31
# arguments:
32
#   - error string [required]
33
# return: n/a
30
### 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
#
34 39
function printError {
35 40
  local string="ERROR:   $1"
36

  
37 41
  # if a log file is specified
38
  if [ ! -z $LOG_FILE ]; then
42
  if [ -n "$LOG_FILE" ]; then
39 43
    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
40 44
  fi
41 45
  printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2
42 46
}
43 47

  
44
### print a warning
45
# arguments:
46
#   - warning string [required]
47
# return: n/a
48
### 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
#
48 57
function printWarning {
49 58
  local string="WARNING: $1"
50

  
51 59
  # if a log file is specified
52
  if [ ! -z $LOG_FILE ]; then
60
  if [ -n "$LOG_FILE" ]; then
53 61
    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
54 62
  fi
55
  printf "$(tput setaf 3)>>> $string$(tput sgr 0)" 1>&2
63
  printf "$(tput setaf 3)>>> $string$(tput sgr 0)"
56 64
}
57 65

  
58
### print an information text
59
# arguments:
60
#   - information string [required]
61
# return: n/a
66
### 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
#
62 75
function printInfo {
63 76
  local string="INFO:    $1"
64

  
65 77
  # if a log file is specified
66
  if [ ! -z $LOG_FILE ]; then
78
  if [ -n "$LOG_FILE" ]; then
67 79
    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
68 80
  fi
69
  printf "$(tput setaf 2)>>> $string$(tput sgr 0)" 1>&2
81
  printf "$(tput setaf 2)>>> $string$(tput sgr 0)"
70 82
}
71 83

  
72
### print a message to the log file
73
# arguments:
74
#   - information string [required]
75
# return: n/a
84
### 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
#
76 92
function printLog {
77 93
  local string="LOG:     $1"
78

  
79 94
  # if a log file is specified
80
  if [ ! -z $LOG_FILE ]; then
95
  if [ -n "$LOG_FILE" ]; then
81 96
    printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE
82 97
  fi
83 98
}
84 99

  
85
### exit the script normally
86
# arguments: n/a
87
# return: 0 (success)
100
### 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
#
88 108
function quitScript {
89
  printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n"
90
  printf "\n"
109
  printLog "exiting $(realpath ${BASH_SOURCE[0]})\n"
91 110
  printf "######################################################################\n"
92

  
93 111
  exit 0
94 112
}
95 113

  
96
### read a user input
97
# arguments:
98
#   --numchars, -n  maximum number of characters to read
99
#   --options, -o   possible chacters to select (only applies if numchars=1)
100
#   --out, -e       output variable to store the user input to
101
# return: error code
102
#   -  0: no error
103
#   - -1: error: invalid arguments
114
### read a user input ##########################################################
115
# Reads a single character user input from a set up <options> and stores it in
116
# a given <return> variable.
117
#
118
# usage:      readUserInput <options> <return>
119
# arguments:  <options>
120
#                 String definiing the set of valid characters.
121
#                 If the string is empty, the user can input any character.
122
#             <return>
123
#                 Variable to store the selected character to.
124
# return:     n/a
125
#
104 126
function readUserInput {
105
  # parse arguments
106
  local arguments=$(getopt -l num-chars:,options:,out: -o n:o:e: -- "$@")
107
  if [ $? != 0 ]; then
108
    printError "could not interprete arguments."
109
    return -1
110
  fi
111
  eval set -- "$arguments"
112

  
113
  # evaluate arguments
114
  local numchars=0
115
  local options=""
116
  local outvar=""
117
  while [ true ]; do
118
    case "$1" in
119
      --num-chars|-n)
120
        numchars=$2; shift 2
121
        ;;
122
      --options|-o)
123
        options="$2"; shift 2
124
        ;;
125
      --out|-e)
126
        outvar=$2; shift 2
127
        ;;
128
      --) # end of options reached
129
        shift; break
130
        ;;
131
      *) # sanity check (return error)
132
        printError "unexpected argument: $1\n"; return -1
133
        ;;
134
    esac
135
  done
136

  
127
  local input=""
137 128
  # read user input
138
  local _userinput=""
139
  while [ -z $_userinput ] || ( [ $numchars == 1 ] && [ ! -z "$options" ] && [[ ! $_userinput =~ ^["$options"]$ ]] ); do
140
    if [ $numchars == 0 ]; then
141
      read -p "your selection: " -e _userinput
142
    else
143
      read -p "your selection: " -n $numchars -e _userinput
144
    fi
145
    if [ -z $_userinput ] || ( [ $numchars == 1 ] && [ ! -z "$options" ] && [[ ! $_userinput =~ ^["$options"]$ ]] ); then
146
      printWarning "[$_userinput] is no valid action\n"
129
  while [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); do
130
    read -p "your selection: " -n 1 -e input
131
    if [ -z $input ] || ( [ -n "$1" ] && [[ ! $input =~ ^[$1]$ ]] ); then
132
      printWarning "[$input] is no valid action\n"
147 133
    fi
148 134
  done
149
  printLog "[$_userinput] has been selected\n"
150
  if [ ! -z "$outvar" ]; then
151
    eval $outvar="$_userinput"
152
  fi
153

  
154
  return 0
135
  printLog "[$input] has been selected\n"
136
  eval $2="$input"
155 137
}
156 138

  
157
### set the log file
158
# arguments:
159
#   --file, -f    name of file [required]
160
#   --option, -o  option if file already exists [optional]
161
#                 a: append
162
#                 r: delete and restart
163
#                 n: disable log
164
#                 A: silent append (no message in the log file)
165
# return: error code
166
#   -  0: no error
167
#   -  1: warning: file already exists
168
#   -  2: warning: no file specified
169
#   - -1: error: invalid arguments
170
function setLogFile {
171
  # parse arguments
172
  local arguments=$(getopt -l file:,option: -o f:o: -- "$@")
173
  if [ $? != 0 ]; then
174
    printError "could not interprete arguments."
139
### check whether argument is an option ########################################
140
# Checks a <string> whether it is an option.
141
# Options are defined to either start with '--' followed by any string, or
142
# to start with a single '-' followed by a single character, or
143
# to start with a single '-' followed by a single character, a '=' and any string.
144
# Examples: '--option', '--option=arg', '-o', '-o=arg', '--'
145
#
146
# usage:      parseIsOption <string>
147
# arguments:  <string>
148
#                 A string to check whether it is an option.
149
# return:     0
150
#                 <string> is an option.
151
#             -1
152
#                 <string> is not an option.
153
#
154
function parseIsOption {
155
  if [[ "$1" =~ ^-(.$|.=.*) ]] || [[ "$1" =~ ^--.* ]]; then
156
    return 0
157
  else
175 158
    return -1
176 159
  fi
177
  eval set -- "$arguments"
160
}
178 161

  
179
  # evaluate arguments
180
  local fname=""
162
### set the log file ###########################################################
163
# Sets a specified <infile> as log file and checks whether it already exists.
164
# If so, the log may either be appended to the file, its content can be cleared,
165
# or no log is generated at all.
166
# The resulting path is stored in <outvar>.
167
#
168
# usage:      setLogFile [--option=<option>] [--quiet] <infile> <outvar>
169
# arguments:  --option=<option>
170
#                 Select what to do if <file> already exists.
171
#                 Possible values are 'a', 'r' and 'n'.
172
#                 - a: append
173
#                 - r: delete and restart
174
#                 - n: no log
175
#                 If no option is secified but <file> exists, an interactive selection is provided.
176
#             --quiet
177
#                 Suppress all messages.
178
#             <infile>
179
#                 Path of the wanted log file.
180
#             <outvar>
181
#                 Variable to store the path of the log file to.
182
# return:     0
183
#                 No error or warning occurred.
184
#             -1
185
#                 Error: invalid input
186
#
187
function setLogFile {
188
  local filepath=""
181 189
  local option=""
182
  while [ true ]; do
183
    case "$1" in
184
      --file|f)
185
        if [ ! -z $2 ]; then
186
          fname="$(dirname $2)/$(basename $2)"
187
        else
188
          fname=""
189
        fi
190
        shift 2
191
        ;;
192
      --option|-o)
193
        case $2 in
194
          A)
195
            option="A"
196
            ;;
197
          a)
198
            option="a"
199
            ;;
200
          r)
201
            option="r"
202
            ;;
203
          n)
204
            option="n"
205
            ;;
206
          *) # sanity check (return error)
207
            printError "unexpected argument: $1\n"; return -1
208
            ;;
209
        esac
210
        shift 2
211
        ;;
212
      --) # end of options reached
213
        shift; break
214
        ;;
215
      *) # sanity check (return error)
216
        printError "unexpected argument: $1\n"; return -1
217
        ;;
218
    esac
190
  local quiet=false
191

  
192
  # parse arguments
193
  local otherargs=()
194
  while [ $# -gt 0 ]; do
195
    if ( parseIsOption $1 ); then
196
      case "$1" in
197
        -o=*|--option=*)
198
          option=${1#*=}; shift 1;;
199
        -o*|--option*)
200
          option="$2"; shift 2;;
201
        -q|--quiet)
202
          quiet=true; shift 1;;
203
        *)
204
          printError "invalid option: $1\n"; shift 1;;
205
      esac
206
    else
207
      otherargs+=("$1")
208
      shift 1
209
    fi
219 210
  done
211
  filepath=$(realpath ${otherargs[0]})
220 212

  
221
  # if no log file was specified
222
  if [ -z $fname ]; then
223
    printWarning "no log file specified (no log will be genreated)\n"
224
    LOG_FILE=""
225
    return 2
226 213
  # if file already exists
227
  elif [ -f $fname ]; then
214
  if [ -e $filepath ]; then
228 215
    # if no option was specified, ask what to do
229
    if [ -z $option ]; then
230
      printWarning "log file ${fname} already esists\n"
231
      printf "Options:\n"
216
    if [ -z "$option" ]; then
217
      printWarning "log file $filepath already esists\n"
218
      local userinput=""
219
      printf "Select what to do:\n"
232 220
      printf "  [A] - append log\n"
233 221
      printf "  [R] - restart log (delete existing file)\n"
234 222
      printf "  [N] - no log\n"
235
      readUserInput --num-chars=1 --options="AaRrNn" --out=userinput
223
      readUserInput "AaRrNn" userinput
236 224
      option=${userinput,,}
237 225
    fi
238

  
239 226
    # evaluate option
240
    case $option in
241
      A)
242
        LOG_FILE=$(realpath $fname)
243
        ;;
227
    case "$option" in
244 228
      a)
245
        printInfo "appending log to existing file\n"
246
        LOG_FILE=$(realpath $fname)
247
        printf "\n" >> $LOG_FILE
248
        printf "######################################################################\n" >> $LOG_FILE
249
        printf "\n" >> $LOG_FILE
229
        if [ $quiet = false ]; then
230
          printInfo "appending log to $filepath\n"
231
        fi
232
        printf "\n" >> $filepath
233
        printf "######################################################################\n" >> $filepath
234
        printf "\n" >> $filepath
250 235
        ;;
251 236
      r)
252
        printInfo "old log file deleted, starting clean\n"
253
        LOG_FILE=$(realpath $fname)
254
        rm $LOG_FILE
237
        echo -n "" > $filepath
238
        if [ $quiet = false ]; then
239
          printInfo "content of $filepath wiped\n"
240
        fi
255 241
        ;;
256 242
      n)
257
        printInfo "no log file will be generated\n"
258
        LOG_FILE=""
243
        if [ $quiet = false ]; then
244
          printInfo "no log file will be generated\n"
245
        fi
246
        filepath=""
259 247
        ;;
260 248
      *) # sanity check (return error)
261
        printError "unexpected argument: $1\n"; return -1
262
        ;;
249
        printError "unexpected argument: $option\n"; return -1;;
263 250
    esac
264

  
265
    return 1
266 251
  else
267
    printInfo "log file set to $(realpath $fname)\n"
268
    LOG_FILE=$(realpath $fname)
269
    return 0
252
    if [ $quiet = false ]; then
253
      printInfo "log file set to $filepath\n"
254
    fi
270 255
  fi
256

  
257
  eval ${otherargs[1]}="$filepath"
258

  
259
  return 0
271 260
}
272 261

  
273 262
################################################################################
274 263
# SPECIFIC FUNCTIONS                                                           #
275 264
################################################################################
276 265

  
277
### print welcome text
278
# arguments: n/a
279
# return: n/a
266
### print welcome text #########################################################
267
# Prints a welcome message to standard out.
268
#
269
# usage:      printWelcomeText
270
# arguments:  n/a
271
# return:     n/a
272
#
280 273
function printWelcomeText {
281 274
  printf "######################################################################\n"
282 275
  printf "#                                                                    #\n"
......
297 290
  printf "######################################################################\n"
298 291
}
299 292

  
300
### print help text
301
# arguments: n/a
302
# return: n/a
293
### print help #################################################################
294
# Prints a help text to standard out.
295
#
296
# usage:      printHelp
297
# arguments:  n/a
298
# return:     n/a
299
#
303 300
function printHelp {
304 301
  printInfo "printing help text\n"
305
  printf "usage:  $(basename ${BASH_SOURCE[0]}) [options]\n"
306
  printf "options:\n"
307
  printf "  --help, -h              Print this help text.\n"
308
  printf "  --clean, -c             Delete project files.\n"
309
  printf "  --wipe, -w              Delete project and .user files.\n"
310
  printf "  --LightRing, -L         Create a project for the LightRing module.\n"
311
  printf "  --PowerManagement, -P   Create a project for the PowerManagement module.\n"
312
  printf "  --DiWheelDrive, -D      Create a project for the DiWheelDrive module.\n"
313
  printf "  --All, -A               Create projects for all modules.\n"
314
  printf "  --quit, -q              Quit the script.\n"
315
  printf "  --log=<file>            Specify a log file.\n"
302
  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [--LightRing] [--PowerManagement] [--DiWheelDrive] [-a|--all] [-q|--quit] [--log=<file>]\n"
303
  printf "\n"
304
  printf "options:  -h, --help\n"
305
  printf "              Print this help text.\n"
306
  printf "          -c, --clean\n"
307
  printf "              Delete project files.\n"
308
  printf "          -w, --wipe\n"
309
  printf "              Delete project and .user files.\n"
310
  printf "          --LightRing\n"
311
  printf "              Create project for the LightRing module.\n"
312
  printf "          --PowerManagement\n"
313
  printf "              Create project for the PowerManagement module.\n"
314
  printf "          --DiWheelDrive\n"
315
  printf "              Create project for the DiWheelDrive module.\n"
316
  printf "          -a, --all\n"
317
  printf "              Create projects for all modules.\n"
318
  printf "          -q, --quit\n"
319
  printf "              Quit the script.\n"
320
  printf "          --log=<file>\n"
321
  printf "              Specify a log file.\n"
316 322
}
317 323

  
318
### read directory where to create/delete projects
319
# arguments:
320
#   - $1: variable to store the path to [required]
321
# return: n/a
324
### read directory where to create/delete projects #############################
325
# Read the directory where to create/delete project files from user.
326
#
327
# usage:      getProjectDir <pathvar>
328
# arguments:  <pathvar>
329
#                 Variable to store the selected path to.
330
# return:     n/a
331
#
322 332
function getProjectDir {
323
  printLog "reading path for project files\n"
324
  local amirobltdir="$(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/)"
325
  local pojectdir=""
326
  read -p "Path where to create/delete project files: " -i $amirobltdir -e projectdir
327
  printLog "user selected path $(realpath $projectdir)\n"
328
  eval $1="$(realpath $projectdir)"
333
  printLog "reading path for project files from user...\n"
334
  local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../Target/)
335
  local input=""
336
  read -p "Path where to create/delete project files: " -i $amirobltdir -e input
337
  printLog "user selected path $(realpath $input)\n"
338
  eval $1="$(realpath $input)"
329 339
}
330 340

  
331
### retrieves the ARM-NONE-EABI-GCC include directory
332
# arguments:
333
#   - $1: variable to store the path to [required]
334
# return:
335
#  -  0: no error
336
#  - -1: error: arm-none-eabi-gcc not found
341
### retrieves the ARM-NONE-EABI-GCC include directory ##########################
342
# Retrieves the include directory of the currently set arm-none-eabi-gcc.
343
#
344
# usage:      retrieveGccIncludeDir <path>
345
# arguments:  <path>
346
#                 Variable to store the path to.
347
# return:    0
348
#                 No error or warning occurred.
349
#            -1
350
#                 Error: Command 'arm-none-eabi-gcc' not found.
351
#
337 352
function retrieveGccIncludeDir {
338 353
  # retrieve binary path or link
339
  local binpath="$(which arm-none-eabi-gcc)"
354
  local binpath=$(which arm-none-eabi-gcc)
340 355
  if [ -z "$binpath" ]; then
341
    printError "arm-none-eabi-gcc not found\n"
356
    printError "command 'arm-none-eabi-gcc' not found\n"
342 357
    return -1
343
  fi
358
  else 
344 359

  
345
  # traverse any links
346
  while [ -L "$binpath" ]; do
347
    binpath=$(readlink $binpath)
348
  done
349
  printInfo "gcc-arm-none-eabi detected: $binpath\n"
360
    # traverse any links
361
    while [ -L "$binpath" ]; do
362
      binpath=$(readlink $binpath)
363
    done
364
    printInfo "gcc-arm-none-eabi detected: $binpath\n"
350 365

  
351
  # return include path
352
  eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
366
    # return include path
367
    eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
353 368

  
354
  return 0
369
    return 0
370
  fi
355 371
}
356 372

  
357
### delete project files
358
# arguments:
359
#  --path, -p <path>  path where to delete the project files
360
#  --out, -o <var>    variable to store the path to
361
#  --wipe, -w         delete .user files as well
373
### delete project files #######################################################
374
# Deletes all project files and optionally .user files, too.
375
#
376
# usage:      deleteProjects [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe]
377
# arguments:  -p, --path <path>
378
#                 Path where to delete the project files.
379
#             -o, --out <var>
380
#                 Variable to store the path to.
381
#             -w, --wipe
382
#                 Delete .user files as well.
362 383
# return:
363 384
#  -  0: no error
364 385
#  -  1: warning: function aborted by user
365 386
#  - -1: error: unexpected user input
366 387
function deleteProjects {
367
  # parse arguments
368
  local arguments=$(getopt -l path:,out:,wipe -o p:o:w -- "$@")
369
  if [ $? != 0 ]; then
370
    printError "could not interprete arguments."
371
    return -1
372
  fi
373
  eval set -- "$arguments"
374

  
375 388
  local projectdir=""
376 389
  local outvar=""
377 390
  local wipe=false
378 391

  
379
  # handle command line arguments
380
  while [ true ]; do
381
    case $1 in
382
      --path|-p)
383
        projectdir="$2"; shift 2
384
        ;;
385
      --out|-o)
386
        outvar=$2; shift 2
387
        ;;
388
      --wipe|-w)
389
        wipe=true; shift 1
390
        ;;
391
      --) # end of options reached
392
        shift; break
393
        ;;
394
      *) # sanity check (exit with error)
395
        printError "unexpected argument: $1\n"; return 1
396
        ;;
397
    esac
392
  # parse arguments
393
  local otherargs=()
394
  while [ $# -gt 0 ]; do
395
    if ( parseIsOption $1 ); then
396
      case "$1" in
397
        -p=*|--path=*)
398
          projectdir=$(realpath "${1#*=}"); shift 1;;
399
        -p|--path)
400
          projectdir=$(realpath "$2"); shift 2;;
401
        -o=*|--out=*)
402
          outvar=${1#*=}; shift 1;;
403
        -o|--out)
404
          outvar=$2; shift 2;;
405
        -w|--wipe)
406
          wipe=true; shift 1;;
407
        *)
408
          printError "invalid option: $1\n"; shift 1;;
409
      esac
410
    else
411
      otherargs+=("$1")
412
      shift 1
413
    fi
398 414
  done
399 415

  
400 416
  # print message
......
440 456
  return 0
441 457
}
442 458

  
443
### create LightRing project files
444
# arguments:
445
#  --path, -p <path>  path where to create the project files
446
#  --out, -o <var>    variable to store the path to
447
# return:
448
#  -  0: no error
449
#  -  1: warning: function aborted by user
450
#  - -1: error: unexpected user input
459
### create LightRing project files #############################################
460
# Create project files for the LightRing module.
461
#
462
# usage:      createLightRingProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
463
# arguments:  -p, --path <path>
464
#                 Path where to create the project files.
465
#             --gcc=<path>
466
#                 Path to the GCC include directory.
467
#             -o, --out <var>
468
#                 Variable to store the path to.
469
#             --gccout=<var>
470
#                 Variable to store the path to the GCC include directory to.
471
# return:     0
472
#                 No error or warning occurred.
473
#
451 474
function createLightRingProject {
452
  # parse arguments
453
  local arguments=$(getopt -l path:,out: -o p:o: -- "$@")
454
  if [ $? != 0 ]; then
455
    printError "could not interprete arguments."
456
    return -1
457
  fi
458
  eval set -- "$arguments"
459

  
460 475
  local projectdir=""
476
  local gccincludedir=""
461 477
  local outvar=""
478
  local gccoutvar=""
462 479

  
463
  # handle command line arguments
464
  while [ true ]; do
465
    case $1 in
466
      --path|-p)
467
        projectdir="$2"; shift 2
468
        ;;
469
      --out|-o)
470
        outvar=$2; shift 2
471
        ;;
472
      --) # end of options reached
473
        shift; break
474
        ;;
475
      *) # sanity check (exit with error)
476
        printError "unexpected argument: $1\n"; return 1
477
        ;;
478
    esac
480
  # parse arguments
481
  local otherargs=()
482
  while [ $# -gt 0 ]; do
483
    if ( parseIsOption $1 ); then
484
      case "$1" in
485
        -p=*|--path=*)
486
          projectdir=$(realpath "${1#*=}"); shift 1;;
487
        -p|--path)
488
          projectdir=$(realpath "$2"); shift 2;;
489
        --gcc=*)
490
          gccincludedir=$(realpath "${1#*=}"); shift 1;;
491
        --gcc)
492
          gccincludedir=$(realpath "$2"); shift 2;;
493
        -o=*|--out=*)
494
          outvar=${1#*=}; shift 1;;
495
        -o|--out)
496
          outvar=$2; shift 2;;
497
        --gccout=*)
498
          gccoutvar=$(realpath "${1#*=}"); shift 1;;
499
        --gccout)
500
          gccoutvar=$(realpath "$2"); shift 2;;
501
        *)
502
          printError "invalid option: $1\n"; shift 1;;
503
      esac
504
    else
505
      otherargs+=("$1")
506
      shift 1
507
    fi
479 508
  done
480 509

  
481 510
  # print message
482
  printInfo "creating QtCreator project files for the LightRing module\n"
511
  printInfo "creating QtCreator project files for the LightRing module...\n"
483 512

  
484 513
  # read project directory if required
485 514
  if [ -z "$projectdir" ]; then
......
487 516
  fi
488 517

  
489 518
  # retrieve gcc-arm-none-eabi include dir
490
  local gccincludedir=""
491
  retrieveGccIncludeDir gccincludedir
492 519
  if [ -z "$gccincludedir" ]; then
493
    return -1
520
    retrieveGccIncludeDir gccincludedir
494 521
  fi
495 522

  
496 523
  # create project files
......
515 542
    echo -e "" >> ${projectdir}/LightRing.creator
516 543
  fi
517 544

  
518
  # store the path to the output variable, if required
545
  # fill the output variables
519 546
  if [ ! -z "$outvar" ]; then
520 547
    eval $outvar="$projectdir"
521 548
  fi
549
  if [ ! -z "$gccoutvar" ]; then
550
    eval $gccoutvar="$gccincludedir"
551
  fi
522 552

  
523 553
  return 0
524 554
}
525 555

  
526
### create PowerManagement project files
527
# arguments:
528
#  --path, -p <path>  path where to create the project files
529
#  --out, -o <var>    variable to store the path to
530
# return:
531
#  -  0: no error
532
#  -  1: warning: function aborted by user
533
#  - -1: error: unexpected user input
556
### create PowerManagement project files #######################################
557
# Create project files for the PowerManagement module.
558
#
559
# usage:      createPowerManagementProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
560
# arguments:  -p, --path <path>
561
#                 Path where to create the project files.
562
#             --gcc=<path>
563
#                 Path to the GCC include directory.
564
#             -o, --out <var>
565
#                 Variable to store the path to.
566
#             --gccout=<var>
567
#                 Variable to store the path to the GCC include directory to.
568
# return:     0
569
#                 No error or warning occurred.
570
#
534 571
function createPowerManagementProject {
535
  # parse arguments
536
  local arguments=$(getopt -l path:,out: -o p:o: -- "$@")
537
  if [ $? != 0 ]; then
538
    printError "could not interprete arguments."
539
    return -1
540
  fi
541
  eval set -- "$arguments"
542

  
543 572
  local projectdir=""
573
  local gccincludedir=""
544 574
  local outvar=""
575
  local gccoutvar=""
545 576

  
546
  # handle command line arguments
547
  while [ true ]; do
548
    case $1 in
549
      --path|-p)
550
        projectdir="$2"; shift 2
551
        ;;
552
      --out|-o)
553
        outvar=$2; shift 2
554
        ;;
555
      --) # end of options reached
556
        shift; break
557
        ;;
558
      *) # sanity check (exit with error)
559
        printError "unexpected argument: $1\n"; return 1
560
        ;;
561
    esac
577
  # parse arguments
578
  local otherargs=()
579
  while [ $# -gt 0 ]; do
580
    if ( parseIsOption $1 ); then
581
      case "$1" in
582
        -p=*|--path=*)
583
          projectdir=$(realpath "${1#*=}"); shift 1;;
584
        -p|--path)
585
          projectdir=$(realpath "$2"); shift 2;;
586
        --gcc=*)
587
          gccincludedir=$(realpath "${1#*=}"); shift 1;;
588
        --gcc)
589
          gccincludedir=$(realpath "$2"); shift 2;;
590
        -o=*|--out=*)
591
          outvar=${1#*=}; shift 1;;
592
        -o|--out)
593
          outvar=$2; shift 2;;
594
        --gccout=*)
595
          gccoutvar=$(realpath "${1#*=}"); shift 1;;
596
        --gccout)
597
          gccoutvar=$(realpath "$2"); shift 2;;
598
        *)
599
          printError "invalid option: $1\n"; shift 1;;
600
      esac
601
    else
602
      otherargs+=("$1")
603
      shift 1
604
    fi
562 605
  done
563 606

  
564 607
  # print message
565
  printInfo "creating QtCreator project files for the PowerManagement module\n"
608
  printInfo "creating QtCreator project files for the PowerManagement module...\n"
566 609

  
567 610
  # read project directory if required
568 611
  if [ -z "$projectdir" ]; then
......
570 613
  fi
571 614

  
572 615
  # retrieve gcc-arm-none-eabi include dir
573
  local gccincludedir=""
574
  retrieveGccIncludeDir gccincludedir
575 616
  if [ -z "$gccincludedir" ]; then
576
    return -1
617
    retrieveGccIncludeDir gccincludedir
577 618
  fi
578 619

  
579 620
  # create project files
580 621
  # generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories)
581 622
  find $gccincludedir -type d > ${projectdir}/PowerManagement.includes
582
  find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM3_STM32" >> ${projectdir}/PowerManagement.includes
623
  find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/PowerManagement.includes
583 624
  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
584 625
  # generate a file that specifies all files
585 626
  echo -n "" > ${projectdir}/PowerManagement.files
......
598 639
    echo -e "" >> ${projectdir}/PowerManagement.creator
599 640
  fi
600 641

  
601
  # store the path to the output variable, if required
642
  # fill the output variables
602 643
  if [ ! -z "$outvar" ]; then
603 644
    eval $outvar="$projectdir"
604 645
  fi
646
  if [ ! -z "$gccoutvar" ]; then
647
    eval $gccoutvar="$gccincludedir"
648
  fi
605 649

  
606 650
  return 0
607 651
}
608 652

  
609
### create DiWheelDrive project files
610
# arguments:
611
#  --path, -p <path>  path where to create the project files
612
#  --out, -o <var>    variable to store the path to
613
# return:
614
#  -  0: no error
615
#  -  1: warning: function aborted by user
616
#  - -1: error: unexpected user input
653
### create DiWheelDrive project files ##########################################
654
# Create project files for the DiWheelDrive module.
655
#
656
# usage:      createDiWheelDriveProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
657
# arguments:  -p, --path <path>
658
#                 Path where to create the project files.
659
#             --gcc=<path>
660
#                 Path to the GCC include directory.
661
#             -o, --out <var>
662
#                 Variable to store the path to.
663
#             --gccout=<var>
664
#                 Variable to store the path to the GCC include directory to.
665
# return:     0
666
#                 No error or warning occurred.
667
#
617 668
function createDiWheelDriveProject {
618
  # parse arguments
619
  local arguments=$(getopt -l path:,out: -o p:o: -- "$@")
620
  if [ $? != 0 ]; then
621
    printError "could not interprete arguments."
622
    return -1
623
  fi
624
  eval set -- "$arguments"
625

  
626 669
  local projectdir=""
670
  local gccincludedir=""
627 671
  local outvar=""
672
  local gccoutvar=""
628 673

  
629
  # handle command line arguments
630
  while [ true ]; do
631
    case $1 in
632
      --path|-p)
633
        projectdir="$2"; shift 2
634
        ;;
635
      --out|-o)
636
        outvar=$2; shift 2
637
        ;;
638
      --) # end of options reached
639
        shift; break
640
        ;;
641
      *) # sanity check (exit with error)
642
        printError "unexpected argument: $1\n"; return 1
643
        ;;
644
    esac
674
  # parse arguments
675
  local otherargs=()
676
  while [ $# -gt 0 ]; do
677
    if ( parseIsOption $1 ); then
678
      case "$1" in
679
        -p=*|--path=*)
680
          projectdir=$(realpath "${1#*=}"); shift 1;;
681
        -p|--path)
682
          projectdir=$(realpath "$2"); shift 2;;
683
        --gcc=*)
684
          gccincludedir=$(realpath "${1#*=}"); shift 1;;
685
        --gcc)
686
          gccincludedir=$(realpath "$2"); shift 2;;
687
        -o=*|--out=*)
688
          outvar=${1#*=}; shift 1;;
689
        -o|--out)
690
          outvar=$2; shift 2;;
691
        --gccout=*)
692
          gccoutvar=$(realpath "${1#*=}"); shift 1;;
693
        --gccout)
694
          gccoutvar=$(realpath "$2"); shift 2;;
695
        *)
696
          printError "invalid option: $1\n"; shift 1;;
697
      esac
698
    else
699
      otherargs+=("$1")
700
      shift 1
701
    fi
645 702
  done
646 703

  
647 704
  # print message
648
  printInfo "creating QtCreator project files for the DiWheelDrive module\n"
705
  printInfo "creating QtCreator project files for the DiWheelDrive module...\n"
649 706

  
650 707
  # read project directory if required
651 708
  if [ -z "$projectdir" ]; then
......
653 710
  fi
654 711

  
655 712
  # retrieve gcc-arm-none-eabi include dir
656
  local gccincludedir=""
657
  retrieveGccIncludeDir gccincludedir
658 713
  if [ -z "$gccincludedir" ]; then
659
    return -1
714
    retrieveGccIncludeDir gccincludedir
660 715
  fi
661 716

  
662 717
  # create project files
......
681 736
    echo -e "" >> ${projectdir}/DiWheelDrive.creator
682 737
  fi
683 738

  
684
  # store the path to the output variable, if required
739
  # fill the output variables
685 740
  if [ ! -z "$outvar" ]; then
686 741
    eval $outvar="$projectdir"
687 742
  fi
743
  if [ ! -z "$gccoutvar" ]; then
744
    eval $gccoutvar="$gccincludedir"
745
  fi
688 746

  
689 747
  return 0
690 748
}
691 749

  
692
### create project files for al modules
693
# arguments:
694
#  --path, -p <path>  path where to create the project files
695
#  --out, -o <var>    variable to store the path to
696
# return:
697
#  -  0: no error
698
#  -  1: warning: function aborted by user
699
#  - -1: error: unexpected user input
750
### create project files for al modules ########################################
751
# Create project files for all modules.
752
#
753
# usage:      createAllProjects
754
# arguments:  n/a
755
# return:     0
756
#                 No error or warning occurred.
757
#
700 758
function createAllProjects {
701
  # parse arguments
702
  local arguments=$(getopt -l path:,out: -o p:o: -- "$@")
703
  if [ $? != 0 ]; then
704
    printError "could not interprete arguments."
705
    return -1
706
  fi
707
  eval set -- "$arguments"
759
  # print message
760
  printInfo "creating QtCreator project files for the DiWheelDrive module...\n"
708 761

  
762
  # read project directory
709 763
  local projectdir=""
710
  local outvar=""
711

  
712
  # handle command line arguments
713
  while [ true ]; do
714
    case $1 in
715
      --path|-p)
716
        projectdir="$2"; shift 2
717
        ;;
718
      --out|-o)
719
        outvar=$2; shift 2
720
        ;;
721
      --) # end of options reached
722
        shift; break
723
        ;;
724
      *) # sanity check (exit with error)
725
        printError "unexpected argument: $1\n"; return 1
726
        ;;
727
    esac
728
  done
729

  
730
  # print message
731
  printInfo "creating QtCreator projects files for all modules\n"
764
  getProjectDir projectdir
765
  printInfo "files will be created in $projectdir\n"
732 766

  
733
  # read project directory if required
734
  if [ -z "$projectdir" ]; then
735
    getProjectDir projectdir
736
  fi
767
  # retrieve gcc-arm-none-eabi include dir
768
  retrieveGccIncludeDir gccincludedir
737 769

  
738 770
  # create projects
739
  createLightRingProject --path="$projectdir"
740
  createPowerManagementProject --path="$projectdir"
741
  createDiWheelDriveProject --path="$projectdir"
742

  
743
  # store the path to the output variable, if required
744
  if [ ! -z "$outvar" ]; then
745
    eval $outvar="$projectdir"
746
  fi
771
  createLightRingProject --path="$projectdir" --gcc="$gccincludedir"
772
  createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir"
773
  createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir"
747 774

  
748 775
  return 0
749 776
}
750 777

  
751
################################################################################
752
# SCRIPT MAIN FUNCTION                                                         #
753
################################################################################
754

  
755
### main function of this script
756
# arguments: see help text
757
# return: error code
758
#   - 0: no error
759
#   - 1: error
778
### main function of this script ###############################################
779
# Creates, deletes and wipes QtCreator project files for the three AMiRo base modules.
780
#
781
# usage:      see function printHelp
782
# arguments:  see function printHelp
783
# return:     0
784
#                 No error or warning ocurred.
785
#
760 786
function main {
761

  
762
  # parse arguments
763
  local arguments=$(getopt -l help,clean,wipe,LightRing,PowerManagement,DiWheelDrive,All,quit,log:,LOG:,noinfo -o hcwLPDAq -- "$@")
764
  if [ $? != 0 ]; then
765
    printError "could not interprete arguments."
766
    exit 1
767
  fi
768
  eval set -- "$arguments"
769

  
770
  # print welcome/info text if not suppressed
787
# print welcome/info text if not suppressed
771 788
  if [[ $@ != *"--noinfo"* ]]; then
772 789
    printWelcomeText
773 790
  else
......
776 793
  printf "\n"
777 794

  
778 795
  # set log file if specified
779
  if [[ $@ == *--log* || $@ == *--LOG* ]]; then
796
  if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then
780 797
    # get the parameter (file name)
781 798
    local cmdidx=1
782
    while [ "${!cmdidx}" != "--log" ] && [ "${!cmdidx}" != "--LOG" ]; do
799
    while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do
783 800
      cmdidx=$[cmdidx + 1]
784 801
    done
785
    local filenameidx=$[cmdidx + 1]
802
    local cmd="${!cmdidx}"
803
    local logfile=""
804
    if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then
805
      logfile=${cmd#*=}
806
    else
807
      local filenameidx=$((cmdidx + 1))
808
      logfile="${!filenameidx}"
809
    fi
786 810
    # optionally force silent appending
787
    if [ "${!cmdidx}" == "--LOG" ]; then
788
      setLogFile --file="${!filenameidx}" --option=A
811
    if [[ "$cmd" = "--LOG"* ]]; then
812
      setLogFile --option=a --quiet "$logfile" LOG_FILE
789 813
    else
790
      setLogFile --file="${!filenameidx}"
814
      setLogFile "$logfile" LOG_FILE
791 815
      printf "\n"
792 816
    fi
793 817
  fi
......
802 826
    quitScript
803 827
  fi
804 828

  
805
  # handle command line arguments
806
  local projectfilesdir=""
807
  while [ true ]; do
808
    case $1 in
809
      --help|-h) # already handled; ignore
810
        shift 1;
811
        ;;
812
      --clean|-c)
813
        if [ -z "$projectfilesdir" ]; then
814
          deleteProjects --out=projectfilesdir
815
        else
816
          deleteProjects --path="$projectfilesdir"
817
        fi
818
        printf "\n"
819
        shift 1
820
        ;;
821
      --wipe|-w)
822
          if [ -z "$projectfilesdir" ]; then
823
          deleteProjects --out=projectfilesdir
824
        else
825
          deleteProjects --wipe --path="$projectfilesdir"
826
        fi
827
        printf "\n"
828
        shift 1
829
        ;;
830
      --LightRing|-L)
831
        if [ -z "$projectfilesdir" ]; then
832
          createLightRingProject --out=projectfilesdir
833
        else
834
          createLightRingProject --path="$projectfilesdir"
835
        fi
836
        printf "\n"
837
        shift 1
838
        ;;
839
      --PowerManagement|-P)
840
        if [ -z "$projectfilesdir" ]; then
841
          createPowerManagementProject --out=projectfilesdir
842
        else
843
          createPowerManagementProject --path="$projectfilesdir"
844
        fi
845
        printf "\n"
846
        shift 1
847
        ;;
848
      --DiWheelDrive|-D)
849
        if [ -z "$projectfilesdir" ]; then
850
          createDiWheelDriveProject --out=projectfilesdir
851
        else
852
          createDiWheelDriveProject --path="$projectfilesdir"
853
        fi
854
        printf "\n"
855
        shift 1
856
        ;;
857
      --All|-A)
858
        if [ -z "$projectfilesdir" ]; then
859
          createAllProjects --out=projectfilesdir
860
        else
861
          createAllProjects --path="$projectfilesdir"
862
        fi
863
        printf "\n"
864
        shift 1
865
        ;;
866
      --quit|-q)
867
        quitScript
868
        ;;
869
      --log|--LOG) # already handled; ignore
870
        shift 2
871
        ;;
872
      --noinfo) # already processed; ignore
873
        shift 1
874
        ;;
875
      --) # end of options reached
876
        shift; break
877
        ;;
878
      *) # sanity check (exit with error)
879
        printError "unexpected argument: $1\n"; exit -1
880
        ;;
881
    esac
829
  # parse arguments
830
  local otherargs=()
831
  while [ $# -gt 0 ]; do
832
    if ( parseIsOption $1 ); then
833
      case "$1" in
834
        -h|--help) # already handled; ignore
835
          shift 1;;
836
        -c|--clean)
837
          deleteProjects; printf "\n"; shift 1;;
838
        -w|--wipe)
839
          deleteProjects --wipe; printf "\n"; shift 1;;
840
        --LightRing)
841
          createLightRingProject; printf "\n"; shift 1;;
842
        --PowerManagement)
843
          createPowerManagementProject; printf "\n"; shift 1;;
844
        --DiWheelDrive)
845
          createDiWheelDriveProject; printf "\n"; shift 1;;
846
        -a|--all)
847
          createAllProjects; printf "\n"; shift 1;;
848
        -q|--quit)
849
          quitScript; shift 1;;
850
        --log=*|--LOG=*) # already handled; ignore
851
          shift 1;;
852
        --log|--LOG) # already handled; ignore
853
          shift 2;;
854
        --noinfo) # already handled; ignore
855
          shift 1;;
856
        *)
857
          printError "invalid option: $1\n"; shift 1;;
858
      esac
859
    else
860
      otherargs+=("$1")
861
      shift 1
862
    fi
882 863
  done
883 864

  
884
  # interactive menu
885
  while [ true ]; do
865
# interactive menu
866
  while ( true ); do
886 867
    # main menu info prompt and selection
887 868
    printInfo "QtCreator setup main menu\n"
888 869
    printf "Please select one of the following actions:\n"
......
893 874
    printf "  [D] - create a project for the DiWheelDrive module\n"
894 875
    printf "  [A] - create a project for all modules\n"
895 876
    printf "  [Q] - quit this setup\n"
896
    readUserInput --num-chars=1 --options="CcWwLlPpDdAaQq" --out=userinput
877
    local userinput=""
878
    readUserInput "CcWwLlPpDdAaQq" userinput
897 879
    printf "\n"
898 880

  
899 881
    # evaluate user selection
900
    case $userinput in
882
    case "$userinput" in
901 883
      C|c)
902
        deleteProjects; printf "\n"
903
        ;;
884
        deleteProjects; printf "\n";;
904 885
      W|w)
905
        deleteProjects --wipe; printf "\n"
906
        ;;
886
        deleteProjects --wipe; printf "\n";;
907 887
      L|l)
908
        createLightRingProject; printf "\n"
909
        ;;
888
        createLightRingProject; printf "\n";;
910 889
      P|p)
911
        createPowerManagementProject; printf "\n"
912
        ;;
890
        createPowerManagementProject; printf "\n";;
913 891
      D|d)
914
        createDiWheelDriveProject; printf "\n"
915
        ;;
892
        createDiWheelDriveProject; printf "\n";;
916 893
      A|a)
917
        createAllProjects; printf "\n"
918
        ;;
894
        createAllProjects; printf "\n";;
919 895
      Q|q)
920
        quitScript
921
        ;;
896
        quitScript;;
922 897
      *) # sanity check (exit with error)
923
        printError "unexpected argument: $userinput\n"; exit -1
924
        ;;
898
        printError "unexpected argument: $userinput\n";;
925 899
    esac
926 900
  done
927 901

  

Also available in: Unified diff