amiro-blt / ide / QtCreator / QtCreatorSetup.sh @ 7a91596e
History | View | Annotate | Download (29.1 KB)
1 |
################################################################################ |
---|---|
2 |
# AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini # |
3 |
# Robot (AMiRo) platform. # |
4 |
# Copyright (C) 2016..2017 Thomas Schöpping et al. # |
5 |
# # |
6 |
# This program is free software: you can redistribute it and/or modify # |
7 |
# it under the terms of the GNU General Public License as published by # |
8 |
# the Free Software Foundation, either version 3 of the License, or # |
9 |
# (at your option) any later version. # |
10 |
# # |
11 |
# This program is distributed in the hope that it will be useful, # |
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
14 |
# GNU General Public License for more details. # |
15 |
# # |
16 |
# You should have received a copy of the GNU General Public License # |
17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
18 |
# # |
19 |
# This research/work was supported by the Cluster of Excellence Cognitive # |
20 |
# Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is # |
21 |
# funded by the German Research Foundation (DFG). # |
22 |
################################################################################ |
23 |
|
24 |
#!/bin/bash |
25 |
|
26 |
################################################################################ |
27 |
# GENERIC FUNCTIONS # |
28 |
################################################################################ |
29 |
|
30 |
### print an error |
31 |
# arguments: |
32 |
# - error string [required] |
33 |
# return: n/a |
34 |
function printError { |
35 |
local string="ERROR: $1" |
36 |
|
37 |
# if a log file is specified |
38 |
if [ ! -z $LOG_FILE ]; then |
39 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
40 |
fi |
41 |
printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2 |
42 |
} |
43 |
|
44 |
### print a warning |
45 |
# arguments: |
46 |
# - warning string [required] |
47 |
# return: n/a |
48 |
function printWarning { |
49 |
local string="WARNING: $1" |
50 |
|
51 |
# if a log file is specified |
52 |
if [ ! -z $LOG_FILE ]; then |
53 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
54 |
fi |
55 |
printf "$(tput setaf 3)>>> $string$(tput sgr 0)" 1>&2 |
56 |
} |
57 |
|
58 |
### print an information text |
59 |
# arguments: |
60 |
# - information string [required] |
61 |
# return: n/a |
62 |
function printInfo { |
63 |
local string="INFO: $1" |
64 |
|
65 |
# if a log file is specified |
66 |
if [ ! -z $LOG_FILE ]; then |
67 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
68 |
fi |
69 |
printf "$(tput setaf 2)>>> $string$(tput sgr 0)" 1>&2 |
70 |
} |
71 |
|
72 |
### print a message to the log file |
73 |
# arguments: |
74 |
# - information string [required] |
75 |
# return: n/a |
76 |
function printLog { |
77 |
local string="LOG: $1" |
78 |
|
79 |
# if a log file is specified |
80 |
if [ ! -z $LOG_FILE ]; then |
81 |
printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
82 |
fi |
83 |
} |
84 |
|
85 |
### exit the script normally |
86 |
# arguments: n/a |
87 |
# return: 0 (success) |
88 |
function quitScript { |
89 |
printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n" |
90 |
printf "\n" |
91 |
printf "######################################################################\n" |
92 |
|
93 |
exit 0 |
94 |
} |
95 |
|
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 |
104 |
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 |
|
137 |
# 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" |
147 |
fi |
148 |
done |
149 |
printLog "[$_userinput] has been selected\n" |
150 |
if [ ! -z "$outvar" ]; then |
151 |
eval $outvar="$_userinput" |
152 |
fi |
153 |
|
154 |
return 0 |
155 |
} |
156 |
|
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." |
175 |
return -1 |
176 |
fi |
177 |
eval set -- "$arguments" |
178 |
|
179 |
# evaluate arguments |
180 |
local fname="" |
181 |
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 |
219 |
done |
220 |
|
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 |
# if file already exists |
227 |
elif [ -f $fname ]; then |
228 |
# 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" |
232 |
printf " [A] - append log\n" |
233 |
printf " [R] - restart log (delete existing file)\n" |
234 |
printf " [N] - no log\n" |
235 |
readUserInput --num-chars=1 --options="AaRrNn" --out=userinput |
236 |
option=${userinput,,} |
237 |
fi |
238 |
|
239 |
# evaluate option |
240 |
case $option in |
241 |
A) |
242 |
LOG_FILE=$(realpath $fname) |
243 |
;; |
244 |
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 |
250 |
;; |
251 |
r) |
252 |
printInfo "old log file deleted, starting clean\n" |
253 |
LOG_FILE=$(realpath $fname) |
254 |
rm $LOG_FILE |
255 |
;; |
256 |
n) |
257 |
printInfo "no log file will be generated\n" |
258 |
LOG_FILE="" |
259 |
;; |
260 |
*) # sanity check (return error) |
261 |
printError "unexpected argument: $1\n"; return -1 |
262 |
;; |
263 |
esac |
264 |
|
265 |
return 1 |
266 |
else |
267 |
printInfo "log file set to $(realpath $fname)\n" |
268 |
LOG_FILE=$(realpath $fname) |
269 |
return 0 |
270 |
fi |
271 |
} |
272 |
|
273 |
################################################################################ |
274 |
# SPECIFIC FUNCTIONS # |
275 |
################################################################################ |
276 |
|
277 |
### print welcome text |
278 |
# arguments: n/a |
279 |
# return: n/a |
280 |
function printWelcomeText { |
281 |
printf "######################################################################\n" |
282 |
printf "# #\n" |
283 |
printf "# Welcome to the QtCreator setup! #\n" |
284 |
printf "# #\n" |
285 |
printf "######################################################################\n" |
286 |
printf "# #\n" |
287 |
printf "# Copyright (c) 2016..2017 Thomas Schöpping #\n" |
288 |
printf "# #\n" |
289 |
printf "# This is free software; see the source for copying conditions. #\n" |
290 |
printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
291 |
printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
292 |
printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
293 |
printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
294 |
printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
295 |
printf "# Excellence Initiative. #\n" |
296 |
printf "# #\n" |
297 |
printf "######################################################################\n" |
298 |
} |
299 |
|
300 |
### print help text |
301 |
# arguments: n/a |
302 |
# return: n/a |
303 |
function printHelp { |
304 |
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" |
316 |
} |
317 |
|
318 |
### read directory where to create/delete projects |
319 |
# arguments: |
320 |
# - $1: variable to store the path to [required] |
321 |
# return: n/a |
322 |
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)" |
329 |
} |
330 |
|
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 |
337 |
function retrieveGccIncludeDir { |
338 |
# retrieve binary path or link |
339 |
local binpath="$(which arm-none-eabi-gcc)" |
340 |
if [ -z "$binpath" ]; then |
341 |
printError "arm-none-eabi-gcc not found\n" |
342 |
return -1 |
343 |
fi |
344 |
|
345 |
# traverse any links |
346 |
while [ -L "$binpath" ]; do |
347 |
binpath=$(readlink $binpath) |
348 |
done |
349 |
printInfo "gcc-arm-none-eabi detected: $binpath\n" |
350 |
|
351 |
# return include path |
352 |
eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/) |
353 |
|
354 |
return 0 |
355 |
} |
356 |
|
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 |
362 |
# return: |
363 |
# - 0: no error |
364 |
# - 1: warning: function aborted by user |
365 |
# - -1: error: unexpected user input |
366 |
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 |
local projectdir="" |
376 |
local outvar="" |
377 |
local wipe=false |
378 |
|
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 |
398 |
done |
399 |
|
400 |
# print message |
401 |
if [ $wipe != true ]; then |
402 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n" |
403 |
else |
404 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n" |
405 |
fi |
406 |
|
407 |
# read project directory if required |
408 |
if [ -z "$projectdir" ]; then |
409 |
getProjectDir projectdir |
410 |
fi |
411 |
|
412 |
# remove all project files |
413 |
rm ${projectdir}/LightRing.includes 2>&1 | tee -a $LOG_FILE |
414 |
rm ${projectdir}/PowerManagement.includes 2>&1 | tee -a $LOG_FILE |
415 |
rm ${projectdir}/DiWheelDrive.includes 2>&1 | tee -a $LOG_FILE |
416 |
|
417 |
rm ${projectdir}/LightRing.files 2>&1 | tee -a $LOG_FILE |
418 |
rm ${projectdir}/PowerManagement.files 2>&1 | tee -a $LOG_FILE |
419 |
rm ${projectdir}/DiWheelDrive.files 2>&1 | tee -a $LOG_FILE |
420 |
|
421 |
rm ${projectdir}/LightRing.config 2>&1 | tee -a $LOG_FILE |
422 |
rm ${projectdir}/PowerManagement.config 2>&1 | tee -a $LOG_FILE |
423 |
rm ${projectdir}/DiWheelDrive.config 2>&1 | tee -a $LOG_FILE |
424 |
|
425 |
rm ${projectdir}/LightRing.creator 2>&1 | tee -a $LOG_FILE |
426 |
rm ${projectdir}/PowerManagement.creator 2>&1 | tee -a $LOG_FILE |
427 |
rm ${projectdir}/DiWheelDrive.creator 2>&1 | tee -a $LOG_FILE |
428 |
|
429 |
if [ $wipe == true ]; then |
430 |
rm ${projectdir}/LightRing.user 2>&1 | tee -a $LOG_FILE |
431 |
rm ${projectdir}/PowerManagement.user 2>&1 | tee -a $LOG_FILE |
432 |
rm ${projectdir}/DiWheelDrive.user 2>&1 | tee -a $LOG_FILE |
433 |
fi |
434 |
|
435 |
# store the path to the output variable, if required |
436 |
if [ ! -z "$outvar" ]; then |
437 |
eval $outvar="$projectdir" |
438 |
fi |
439 |
|
440 |
return 0 |
441 |
} |
442 |
|
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 |
451 |
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 |
local projectdir="" |
461 |
local outvar="" |
462 |
|
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 |
479 |
done |
480 |
|
481 |
# print message |
482 |
printInfo "creating QtCreator project files for the LightRing module\n" |
483 |
|
484 |
# read project directory if required |
485 |
if [ -z "$projectdir" ]; then |
486 |
getProjectDir projectdir |
487 |
fi |
488 |
|
489 |
# retrieve gcc-arm-none-eabi include dir |
490 |
local gccincludedir="" |
491 |
retrieveGccIncludeDir gccincludedir |
492 |
if [ -z "$gccincludedir" ]; then |
493 |
return -1 |
494 |
fi |
495 |
|
496 |
# create project files |
497 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
498 |
find $gccincludedir -type d > ${projectdir}/LightRing.includes |
499 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/LightRing.includes |
500 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_LightRing_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/LightRing.includes |
501 |
# generate a file that specifies all files |
502 |
echo -n "" > ${projectdir}/LightRing.files |
503 |
for path in `cat ${projectdir}/LightRing.includes`; do |
504 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/LightRing.files |
505 |
done |
506 |
# generate a default project configuration file if none exists so far |
507 |
if [ ! -f ${projectdir}/LightRing.config ]; then |
508 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/LightRing.config |
509 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/LightRing.config |
510 |
echo -e "" >> ${projectdir}/LightRing.config |
511 |
fi |
512 |
# generate a default .creator file if none exists so far |
513 |
if [ ! -f ${projectdir}/LightRing.creator ]; then |
514 |
echo -e "[general]" > ${projectdir}/LightRing.creator |
515 |
echo -e "" >> ${projectdir}/LightRing.creator |
516 |
fi |
517 |
|
518 |
# store the path to the output variable, if required |
519 |
if [ ! -z "$outvar" ]; then |
520 |
eval $outvar="$projectdir" |
521 |
fi |
522 |
|
523 |
return 0 |
524 |
} |
525 |
|
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 |
534 |
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 |
local projectdir="" |
544 |
local outvar="" |
545 |
|
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 |
562 |
done |
563 |
|
564 |
# print message |
565 |
printInfo "creating QtCreator project files for the PowerManagement module\n" |
566 |
|
567 |
# read project directory if required |
568 |
if [ -z "$projectdir" ]; then |
569 |
getProjectDir projectdir |
570 |
fi |
571 |
|
572 |
# retrieve gcc-arm-none-eabi include dir |
573 |
local gccincludedir="" |
574 |
retrieveGccIncludeDir gccincludedir |
575 |
if [ -z "$gccincludedir" ]; then |
576 |
return -1 |
577 |
fi |
578 |
|
579 |
# create project files |
580 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
581 |
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 |
583 |
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 |
# generate a file that specifies all files |
585 |
echo -n "" > ${projectdir}/PowerManagement.files |
586 |
for path in `cat ${projectdir}/PowerManagement.includes`; do |
587 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/PowerManagement.files |
588 |
done |
589 |
# generate a default project configuration file if none exists so far |
590 |
if [ ! -f ${projectdir}/PowerManagement.config ]; then |
591 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/PowerManagement.config |
592 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/PowerManagement.config |
593 |
echo -e "" >> ${projectdir}/PowerManagement.config |
594 |
fi |
595 |
# generate a default .creator file if none exists so far |
596 |
if [ ! -f ${projectdir}/PowerManagement.creator ]; then |
597 |
echo -e "[general]" > ${projectdir}/PowerManagement.creator |
598 |
echo -e "" >> ${projectdir}/PowerManagement.creator |
599 |
fi |
600 |
|
601 |
# store the path to the output variable, if required |
602 |
if [ ! -z "$outvar" ]; then |
603 |
eval $outvar="$projectdir" |
604 |
fi |
605 |
|
606 |
return 0 |
607 |
} |
608 |
|
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 |
617 |
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 |
local projectdir="" |
627 |
local outvar="" |
628 |
|
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 |
645 |
done |
646 |
|
647 |
# print message |
648 |
printInfo "creating QtCreator project files for the DiWheelDrive module\n" |
649 |
|
650 |
# read project directory if required |
651 |
if [ -z "$projectdir" ]; then |
652 |
getProjectDir projectdir |
653 |
fi |
654 |
|
655 |
# retrieve gcc-arm-none-eabi include dir |
656 |
local gccincludedir="" |
657 |
retrieveGccIncludeDir gccincludedir |
658 |
if [ -z "$gccincludedir" ]; then |
659 |
return -1 |
660 |
fi |
661 |
|
662 |
# create project files |
663 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
664 |
find $gccincludedir -type d > ${projectdir}/DiWheelDrive.includes |
665 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/DiWheelDrive.includes |
666 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_DiWheelDrive_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/DiWheelDrive.includes |
667 |
# generate a file that specifies all files |
668 |
echo -n "" > ${projectdir}/DiWheelDrive.files |
669 |
for path in `cat ${projectdir}/DiWheelDrive.includes`; do |
670 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/DiWheelDrive.files |
671 |
done |
672 |
# generate a default project configuration file if none exists so far |
673 |
if [ ! -f ${projectdir}/DiWheelDrive.config ]; then |
674 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/DiWheelDrive.config |
675 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/DiWheelDrive.config |
676 |
echo -e "" >> ${projectdir}/DiWheelDrive.config |
677 |
fi |
678 |
# generate a default .creator file if none exists so far |
679 |
if [ ! -f ${projectdir}/DiWheelDrive.creator ]; then |
680 |
echo -e "[general]" > ${projectdir}/DiWheelDrive.creator |
681 |
echo -e "" >> ${projectdir}/DiWheelDrive.creator |
682 |
fi |
683 |
|
684 |
# store the path to the output variable, if required |
685 |
if [ ! -z "$outvar" ]; then |
686 |
eval $outvar="$projectdir" |
687 |
fi |
688 |
|
689 |
return 0 |
690 |
} |
691 |
|
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 |
700 |
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" |
708 |
|
709 |
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" |
732 |
|
733 |
# read project directory if required |
734 |
if [ -z "$projectdir" ]; then |
735 |
getProjectDir projectdir |
736 |
fi |
737 |
|
738 |
# 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 |
747 |
|
748 |
return 0 |
749 |
} |
750 |
|
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 |
760 |
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 |
771 |
if [[ $@ != *"--noinfo"* ]]; then |
772 |
printWelcomeText |
773 |
else |
774 |
printf "######################################################################\n" |
775 |
fi |
776 |
printf "\n" |
777 |
|
778 |
# set log file if specified |
779 |
if [[ $@ == *--log* || $@ == *--LOG* ]]; then |
780 |
# get the parameter (file name) |
781 |
local cmdidx=1 |
782 |
while [ "${!cmdidx}" != "--log" ] && [ "${!cmdidx}" != "--LOG" ]; do |
783 |
cmdidx=$[cmdidx + 1] |
784 |
done |
785 |
local filenameidx=$[cmdidx + 1] |
786 |
# optionally force silent appending |
787 |
if [ "${!cmdidx}" == "--LOG" ]; then |
788 |
setLogFile --file="${!filenameidx}" --option=A |
789 |
else |
790 |
setLogFile --file="${!filenameidx}" |
791 |
printf "\n" |
792 |
fi |
793 |
fi |
794 |
|
795 |
# log script name |
796 |
printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
797 |
|
798 |
# if --help or -h was specified, print the help text and exit |
799 |
if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
800 |
printHelp |
801 |
printf "\n" |
802 |
quitScript |
803 |
fi |
804 |
|
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 |
882 |
done |
883 |
|
884 |
# interactive menu |
885 |
while [ true ]; do |
886 |
# main menu info prompt and selection |
887 |
printInfo "QtCreator setup main menu\n" |
888 |
printf "Please select one of the following actions:\n" |
889 |
printf " [C] - clean project files\n" |
890 |
printf " [W] - wipe project and .user files\n" |
891 |
printf " [L] - create a project for the LightRing module\n" |
892 |
printf " [P] - create a project for the PowerManagement module\n" |
893 |
printf " [D] - create a project for the DiWheelDrive module\n" |
894 |
printf " [A] - create a project for all modules\n" |
895 |
printf " [Q] - quit this setup\n" |
896 |
readUserInput --num-chars=1 --options="CcWwLlPpDdAaQq" --out=userinput |
897 |
printf "\n" |
898 |
|
899 |
# evaluate user selection |
900 |
case $userinput in |
901 |
C|c) |
902 |
deleteProjects; printf "\n" |
903 |
;; |
904 |
W|w) |
905 |
deleteProjects --wipe; printf "\n" |
906 |
;; |
907 |
L|l) |
908 |
createLightRingProject; printf "\n" |
909 |
;; |
910 |
P|p) |
911 |
createPowerManagementProject; printf "\n" |
912 |
;; |
913 |
D|d) |
914 |
createDiWheelDriveProject; printf "\n" |
915 |
;; |
916 |
A|a) |
917 |
createAllProjects; printf "\n" |
918 |
;; |
919 |
Q|q) |
920 |
quitScript |
921 |
;; |
922 |
*) # sanity check (exit with error) |
923 |
printError "unexpected argument: $userinput\n"; exit -1 |
924 |
;; |
925 |
esac |
926 |
done |
927 |
|
928 |
exit 0 |
929 |
} |
930 |
|
931 |
################################################################################ |
932 |
# SCRIPT ENTRY POINT # |
933 |
################################################################################ |
934 |
|
935 |
main "$@" |
936 |
|