amiro-blt / tools / ide / QtCreator / QtCreatorSetup.sh @ c1f21a71
History | View | Annotate | Download (33.127 KB)
1 |
################################################################################ |
---|---|
2 |
# AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini # |
3 |
# Robot (AMiRo) platform. # |
4 |
# Copyright (C) 2016..2019 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 |
#!/bin/bash |
25 |
|
26 |
################################################################################ |
27 |
# GENERIC FUNCTIONS # |
28 |
################################################################################ |
29 |
|
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 |
# |
39 |
function printError { |
40 |
local string="ERROR: $1" |
41 |
# if a log file is specified |
42 |
if [ -n "$LOG_FILE" ]; then |
43 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
44 |
fi |
45 |
printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2 |
46 |
} |
47 |
|
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 |
# |
57 |
function printWarning { |
58 |
local string="WARNING: $1" |
59 |
# if a log file is specified |
60 |
if [ -n "$LOG_FILE" ]; then |
61 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
62 |
fi |
63 |
printf "$(tput setaf 3)>>> $string$(tput sgr 0)" |
64 |
} |
65 |
|
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 |
# |
75 |
function printInfo { |
76 |
local string="INFO: $1" |
77 |
# if a log file is specified |
78 |
if [ -n "$LOG_FILE" ]; then |
79 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
80 |
fi |
81 |
printf "$(tput setaf 2)>>> $string$(tput sgr 0)" |
82 |
} |
83 |
|
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 |
# |
92 |
function printLog { |
93 |
local string="LOG: $1" |
94 |
# if a log file is specified |
95 |
if [ -n "$LOG_FILE" ]; then |
96 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
97 |
fi |
98 |
} |
99 |
|
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 |
# |
108 |
function quitScript { |
109 |
printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n" |
110 |
printf "\n" |
111 |
printf "######################################################################\n" |
112 |
exit 0 |
113 |
} |
114 |
|
115 |
### 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 |
function readUserInput { |
128 |
local input="" |
129 |
# read user input |
130 |
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 |
fi |
135 |
done |
136 |
printLog "[$input] has been selected\n" |
137 |
eval $2="$input" |
138 |
} |
139 |
|
140 |
### 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 |
return -1 |
160 |
fi |
161 |
} |
162 |
|
163 |
### 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', 'c', 'r' and 'n'. |
173 |
# - a: append (starts with a separator) |
174 |
# - c: continue (does not insert a seperator) |
175 |
# - 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 |
local option="" |
192 |
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 |
done |
213 |
filepath=$(realpath ${otherargs[0]}) |
214 |
|
215 |
# if file already exists |
216 |
if [ -e $filepath ]; then |
217 |
# if no option was specified, ask what to do |
218 |
if [ -z "$option" ]; then |
219 |
printWarning "log file $filepath already esists\n" |
220 |
local userinput="" |
221 |
printf "Select what to do:\n" |
222 |
printf " [A] - append log\n" |
223 |
printf " [R] - restart log (delete existing file)\n" |
224 |
printf " [N] - no log\n" |
225 |
readUserInput "AaRrNn" userinput |
226 |
option=${userinput,,} |
227 |
fi |
228 |
# evaluate option |
229 |
case "$option" in |
230 |
a|c) |
231 |
if [ $quiet = false ]; then |
232 |
printInfo "appending log to $filepath\n" |
233 |
fi |
234 |
if [ $option != c ]; then |
235 |
printf "\n" >> $filepath |
236 |
printf "######################################################################\n" >> $filepath |
237 |
printf "\n" >> $filepath |
238 |
fi |
239 |
;; |
240 |
r) |
241 |
echo -n "" > $filepath |
242 |
if [ $quiet = false ]; then |
243 |
printInfo "content of $filepath wiped\n" |
244 |
fi |
245 |
;; |
246 |
n) |
247 |
if [ $quiet = false ]; then |
248 |
printInfo "no log file will be generated\n" |
249 |
fi |
250 |
filepath="" |
251 |
;; |
252 |
*) # sanity check (return error) |
253 |
printError "unexpected argument: $option\n"; return -1;; |
254 |
esac |
255 |
else |
256 |
if [ $quiet = false ]; then |
257 |
printInfo "log file set to $filepath\n" |
258 |
fi |
259 |
fi |
260 |
|
261 |
eval ${otherargs[1]}="$filepath" |
262 |
|
263 |
return 0 |
264 |
} |
265 |
|
266 |
### 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 |
################################################################################ |
301 |
# SPECIFIC FUNCTIONS # |
302 |
################################################################################ |
303 |
|
304 |
### 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 |
function printWelcomeText { |
312 |
printf "######################################################################\n" |
313 |
printf "# #\n" |
314 |
printf "# Welcome to the QtCreator setup! #\n" |
315 |
printf "# #\n" |
316 |
printf "######################################################################\n" |
317 |
printf "# #\n" |
318 |
printf "# Copyright (c) 2016..2019 Thomas Schöpping #\n" |
319 |
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 |
} |
330 |
|
331 |
### print help ################################################################# |
332 |
# Prints a help text to standard out. |
333 |
# |
334 |
# usage: printHelp |
335 |
# arguments: n/a |
336 |
# return: n/a |
337 |
# |
338 |
function printHelp { |
339 |
printInfo "printing help text\n" |
340 |
printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [--LightRing] [--PowerManagement] [--DiWheelDrive] [-a|--all] [-q|--quit] [--log=<file>]\n" |
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 |
} |
361 |
|
362 |
### 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 |
function getProjectDir { |
371 |
printLog "reading path for project files from user...\n" |
372 |
local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/) |
373 |
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 |
} |
378 |
|
379 |
### 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 |
function retrieveGccIncludeDir { |
391 |
# retrieve binary path or link |
392 |
local binpath=$(which arm-none-eabi-gcc) |
393 |
if [ -z "$binpath" ]; then |
394 |
printError "command 'arm-none-eabi-gcc' not found\n" |
395 |
return -1 |
396 |
else |
397 |
|
398 |
# traverse any links |
399 |
while [ -L "$binpath" ]; do |
400 |
binpath=$(realpath $(dirname $binpath)/$(readlink $binpath)) |
401 |
done |
402 |
printInfo "gcc-arm-none-eabi detected: $binpath\n" |
403 |
|
404 |
# return include path |
405 |
eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/) |
406 |
|
407 |
return 0 |
408 |
fi |
409 |
} |
410 |
|
411 |
### 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 |
# 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 |
|
430 |
# parse arguments |
431 |
local otherargs=() |
432 |
while [ $# -gt 0 ]; do |
433 |
if ( parseIsOption $1 ); then |
434 |
case "$1" in |
435 |
-p=*|--path=*) |
436 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
437 |
-p|--path) |
438 |
projectdir=$(realpath "$2"); shift 2;; |
439 |
-o=*|--out=*) |
440 |
outvar=${1#*=}; shift 1;; |
441 |
-o|--out) |
442 |
outvar=$2; shift 2;; |
443 |
-w|--wipe) |
444 |
wipe=true; shift 1;; |
445 |
*) |
446 |
printError "invalid option: $1\n"; shift 1;; |
447 |
esac |
448 |
else |
449 |
otherargs+=("$1") |
450 |
shift 1 |
451 |
fi |
452 |
done |
453 |
|
454 |
# print message |
455 |
if [ $wipe != true ]; then |
456 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n" |
457 |
else |
458 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n" |
459 |
fi |
460 |
|
461 |
# read project directory if required |
462 |
if [ -z "$projectdir" ]; then |
463 |
getProjectDir projectdir |
464 |
fi |
465 |
|
466 |
# remove all project files |
467 |
rm ${projectdir}/LightRing.includes 2>&1 | tee -a $LOG_FILE |
468 |
rm ${projectdir}/PowerManagement.includes 2>&1 | tee -a $LOG_FILE |
469 |
rm ${projectdir}/DiWheelDrive.includes 2>&1 | tee -a $LOG_FILE |
470 |
|
471 |
rm ${projectdir}/LightRing.files 2>&1 | tee -a $LOG_FILE |
472 |
rm ${projectdir}/PowerManagement.files 2>&1 | tee -a $LOG_FILE |
473 |
rm ${projectdir}/DiWheelDrive.files 2>&1 | tee -a $LOG_FILE |
474 |
|
475 |
rm ${projectdir}/LightRing.config 2>&1 | tee -a $LOG_FILE |
476 |
rm ${projectdir}/PowerManagement.config 2>&1 | tee -a $LOG_FILE |
477 |
rm ${projectdir}/DiWheelDrive.config 2>&1 | tee -a $LOG_FILE |
478 |
|
479 |
rm ${projectdir}/LightRing.creator 2>&1 | tee -a $LOG_FILE |
480 |
rm ${projectdir}/PowerManagement.creator 2>&1 | tee -a $LOG_FILE |
481 |
rm ${projectdir}/DiWheelDrive.creator 2>&1 | tee -a $LOG_FILE |
482 |
|
483 |
if [ $wipe == true ]; then |
484 |
rm ${projectdir}/LightRing.creator.user 2>&1 | tee -a $LOG_FILE |
485 |
rm ${projectdir}/PowerManagement.creator.user 2>&1 | tee -a $LOG_FILE |
486 |
rm ${projectdir}/DiWheelDrive.creator.user 2>&1 | tee -a $LOG_FILE |
487 |
fi |
488 |
|
489 |
# store the path to the output variable, if required |
490 |
if [ ! -z "$outvar" ]; then |
491 |
eval $outvar="$projectdir" |
492 |
fi |
493 |
|
494 |
return 0 |
495 |
} |
496 |
|
497 |
### 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 |
function createLightRingProject { |
513 |
local userdir=$(pwd) |
514 |
local projectdir="" |
515 |
local gccincludedir="" |
516 |
local outvar="" |
517 |
local gccoutvar="" |
518 |
|
519 |
# 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 |
done |
548 |
|
549 |
# print message |
550 |
printInfo "creating QtCreator project files for the LightRing module...\n" |
551 |
|
552 |
# read absolute project directory if required |
553 |
if [ -z "$projectdir" ]; then |
554 |
getProjectDir projectdir |
555 |
fi |
556 |
|
557 |
# retrieve absolute GCC include dir |
558 |
if [ -z "$gccincludedir" ]; then |
559 |
retrieveGccIncludeDir gccincludedir |
560 |
fi |
561 |
|
562 |
# move to project directory |
563 |
cd $projectdir |
564 |
|
565 |
# create project files |
566 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
567 |
find $gccincludedir -type d > ${projectdir}/LightRing.includes |
568 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Source) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/LightRing.includes |
569 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Modules/LightRing_1-0/Boot) -type d | grep -v "bin\|cmd\|ethernetlib\|fatfs\|uip\|obj" >> ${projectdir}/LightRing.includes |
570 |
# generate a file that specifies all files |
571 |
echo -n "" > ${projectdir}/LightRing.files |
572 |
for path in `cat ${projectdir}/LightRing.includes`; do |
573 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/LightRing.files |
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 |
# go back to user directory |
588 |
cd $userdir |
589 |
|
590 |
# fill the output variables |
591 |
if [ ! -z "$outvar" ]; then |
592 |
eval $outvar="$projectdir" |
593 |
fi |
594 |
if [ ! -z "$gccoutvar" ]; then |
595 |
eval $gccoutvar="$gccincludedir" |
596 |
fi |
597 |
|
598 |
return 0 |
599 |
} |
600 |
|
601 |
### 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 |
function createPowerManagementProject { |
617 |
local userdir=$(pwd) |
618 |
local projectdir="" |
619 |
local gccincludedir="" |
620 |
local outvar="" |
621 |
local gccoutvar="" |
622 |
|
623 |
# 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 |
done |
652 |
|
653 |
# print message |
654 |
printInfo "creating QtCreator project files for the PowerManagement module...\n" |
655 |
|
656 |
# read absolute project directory if required |
657 |
if [ -z "$projectdir" ]; then |
658 |
getProjectDir projectdir |
659 |
fi |
660 |
|
661 |
# retrieve absolute GCC include dir |
662 |
if [ -z "$gccincludedir" ]; then |
663 |
retrieveGccIncludeDir gccincludedir |
664 |
fi |
665 |
|
666 |
# move to project directory |
667 |
cd $projectdir |
668 |
|
669 |
# create project files |
670 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
671 |
find $gccincludedir -type d > ${projectdir}/PowerManagement.includes |
672 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Source) -type d | grep -v "ARMCM3_STM32" >> ${projectdir}/PowerManagement.includes |
673 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Modules/PowerManagement_1-1/Boot) -type d | grep -v "bin\|cmd\|ethernetlib\|fatfs\|uip\|obj" >> ${projectdir}/PowerManagement.includes |
674 |
# generate a file that specifies all files |
675 |
echo -n "" > ${projectdir}/PowerManagement.files |
676 |
for path in `cat ${projectdir}/PowerManagement.includes`; do |
677 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/PowerManagement.files |
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 |
|
691 |
# go back to user directory |
692 |
cd $userdir |
693 |
|
694 |
|
695 |
# fill the output variables |
696 |
if [ ! -z "$outvar" ]; then |
697 |
eval $outvar="$projectdir" |
698 |
fi |
699 |
if [ ! -z "$gccoutvar" ]; then |
700 |
eval $gccoutvar="$gccincludedir" |
701 |
fi |
702 |
|
703 |
return 0 |
704 |
} |
705 |
|
706 |
### 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 |
function createDiWheelDriveProject { |
722 |
local userdir=$(pwd) |
723 |
local projectdir="" |
724 |
local gccincludedir="" |
725 |
local outvar="" |
726 |
local gccoutvar="" |
727 |
|
728 |
# 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 |
done |
757 |
|
758 |
# print message |
759 |
printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
760 |
|
761 |
# read absolute project directory if required |
762 |
if [ -z "$projectdir" ]; then |
763 |
getProjectDir projectdir |
764 |
fi |
765 |
|
766 |
# retrieve absolute GCC include dir |
767 |
if [ -z "$gccincludedir" ]; then |
768 |
retrieveGccIncludeDir gccincludedir |
769 |
fi |
770 |
|
771 |
# move to project directory |
772 |
cd $projectdir |
773 |
|
774 |
|
775 |
# create project files |
776 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
777 |
find $gccincludedir -type d > ${projectdir}/DiWheelDrive.includes |
778 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Source) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/DiWheelDrive.includes |
779 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../Target/Modules/DiWheelDrive_1-1/Boot) -type d | grep -v "bin\|cmd\|ethernetlib\|fatfs\|uip\|obj" >> ${projectdir}/DiWheelDrive.includes |
780 |
# generate a file that specifies all files |
781 |
echo -n "" > ${projectdir}/DiWheelDrive.files |
782 |
for path in `cat ${projectdir}/DiWheelDrive.includes`; do |
783 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/DiWheelDrive.files |
784 |
done |
785 |
# generate a default project configuration file if none exists so far |
786 |
if [ ! -f ${projectdir}/DiWheelDrive.config ]; then |
787 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/DiWheelDrive.config |
788 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/DiWheelDrive.config |
789 |
echo -e "" >> ${projectdir}/DiWheelDrive.config |
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 |
|
797 |
# go back to user directory |
798 |
cd $userdir |
799 |
|
800 |
|
801 |
# fill the output variables |
802 |
if [ ! -z "$outvar" ]; then |
803 |
eval $outvar="$projectdir" |
804 |
fi |
805 |
if [ ! -z "$gccoutvar" ]; then |
806 |
eval $gccoutvar="$gccincludedir" |
807 |
fi |
808 |
|
809 |
return 0 |
810 |
} |
811 |
|
812 |
### create project files for al modules ######################################## |
813 |
# Create project files for all modules. |
814 |
# |
815 |
# usage: createAllProjects |
816 |
# arguments: n/a |
817 |
# return: 0 |
818 |
# No error or warning occurred. |
819 |
# |
820 |
function createAllProjects { |
821 |
# print message |
822 |
printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
823 |
|
824 |
# read project directory |
825 |
local projectdir="" |
826 |
getProjectDir projectdir |
827 |
printInfo "files will be created in $projectdir\n" |
828 |
|
829 |
# retrieve gcc-arm-none-eabi include dir |
830 |
retrieveGccIncludeDir gccincludedir |
831 |
|
832 |
# create projects |
833 |
createLightRingProject --path="$projectdir" --gcc="$gccincludedir" |
834 |
createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir" |
835 |
createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir" |
836 |
|
837 |
return 0 |
838 |
} |
839 |
|
840 |
### 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 |
function main { |
849 |
# print welcome/info text if not suppressed |
850 |
if [[ $@ != *"--noinfo"* ]]; then |
851 |
printWelcomeText |
852 |
else |
853 |
printf "######################################################################\n" |
854 |
fi |
855 |
printf "\n" |
856 |
|
857 |
# 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 |
# set log file if specified |
865 |
if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
866 |
# get the parameter (file name) |
867 |
local cmdidx=1 |
868 |
while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do |
869 |
cmdidx=$[cmdidx + 1] |
870 |
done |
871 |
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 |
# optionally force silent appending |
880 |
if [[ "$cmd" = "--LOG"* ]]; then |
881 |
setLogFile --option=c --quiet "$logfile" LOG_FILE |
882 |
else |
883 |
setLogFile "$logfile" LOG_FILE |
884 |
printf "\n" |
885 |
fi |
886 |
fi |
887 |
# log script name |
888 |
printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
889 |
|
890 |
# 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 |
done |
925 |
|
926 |
# interactive menu |
927 |
while ( true ); do |
928 |
# 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 |
local userinput="" |
939 |
readUserInput "CcWwLlPpDdAaQq" userinput |
940 |
printf "\n" |
941 |
|
942 |
# evaluate user selection |
943 |
case "$userinput" in |
944 |
C|c) |
945 |
deleteProjects; printf "\n";; |
946 |
W|w) |
947 |
deleteProjects --wipe; printf "\n";; |
948 |
L|l) |
949 |
createLightRingProject; printf "\n";; |
950 |
P|p) |
951 |
createPowerManagementProject; printf "\n";; |
952 |
D|d) |
953 |
createDiWheelDriveProject; printf "\n";; |
954 |
A|a) |
955 |
createAllProjects; printf "\n";; |
956 |
Q|q) |
957 |
quitScript;; |
958 |
*) # sanity check (exit with error) |
959 |
printError "unexpected argument: $userinput\n";; |
960 |
esac |
961 |
done |
962 |
|
963 |
exit 0 |
964 |
} |
965 |
|
966 |
################################################################################ |
967 |
# SCRIPT ENTRY POINT # |
968 |
################################################################################ |
969 |
|
970 |
main "$@" |
971 |
|