amiro-blt / ide / QtCreator / QtCreatorSetup.sh @ 1446566f
History | View | Annotate | Download (31.6 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 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', 'r' and 'n'. |
173 |
# - a: append |
174 |
# - r: delete and restart |
175 |
# - n: no log |
176 |
# If no option is secified but <file> exists, an interactive selection is provided. |
177 |
# --quiet |
178 |
# Suppress all messages. |
179 |
# <infile> |
180 |
# Path of the wanted log file. |
181 |
# <outvar> |
182 |
# Variable to store the path of the log file to. |
183 |
# return: 0 |
184 |
# No error or warning occurred. |
185 |
# -1 |
186 |
# Error: invalid input |
187 |
# |
188 |
function setLogFile { |
189 |
local filepath="" |
190 |
local option="" |
191 |
local quiet=false |
192 |
|
193 |
# parse arguments |
194 |
local otherargs=() |
195 |
while [ $# -gt 0 ]; do |
196 |
if ( parseIsOption $1 ); then |
197 |
case "$1" in |
198 |
-o=*|--option=*) |
199 |
option=${1#*=}; shift 1;; |
200 |
-o*|--option*) |
201 |
option="$2"; shift 2;; |
202 |
-q|--quiet) |
203 |
quiet=true; shift 1;; |
204 |
*) |
205 |
printError "invalid option: $1\n"; shift 1;; |
206 |
esac |
207 |
else |
208 |
otherargs+=("$1") |
209 |
shift 1 |
210 |
fi |
211 |
done |
212 |
filepath=$(realpath ${otherargs[0]}) |
213 |
|
214 |
# if file already exists |
215 |
if [ -e $filepath ]; then |
216 |
# if no option was specified, ask what to do |
217 |
if [ -z "$option" ]; then |
218 |
printWarning "log file $filepath already esists\n" |
219 |
local userinput="" |
220 |
printf "Select what to do:\n" |
221 |
printf " [A] - append log\n" |
222 |
printf " [R] - restart log (delete existing file)\n" |
223 |
printf " [N] - no log\n" |
224 |
readUserInput "AaRrNn" userinput |
225 |
option=${userinput,,} |
226 |
fi |
227 |
# evaluate option |
228 |
case "$option" in |
229 |
a) |
230 |
if [ $quiet = false ]; then |
231 |
printInfo "appending log to $filepath\n" |
232 |
fi |
233 |
printf "\n" >> $filepath |
234 |
printf "######################################################################\n" >> $filepath |
235 |
printf "\n" >> $filepath |
236 |
;; |
237 |
r) |
238 |
echo -n "" > $filepath |
239 |
if [ $quiet = false ]; then |
240 |
printInfo "content of $filepath wiped\n" |
241 |
fi |
242 |
;; |
243 |
n) |
244 |
if [ $quiet = false ]; then |
245 |
printInfo "no log file will be generated\n" |
246 |
fi |
247 |
filepath="" |
248 |
;; |
249 |
*) # sanity check (return error) |
250 |
printError "unexpected argument: $option\n"; return -1;; |
251 |
esac |
252 |
else |
253 |
if [ $quiet = false ]; then |
254 |
printInfo "log file set to $filepath\n" |
255 |
fi |
256 |
fi |
257 |
|
258 |
eval ${otherargs[1]}="$filepath" |
259 |
|
260 |
return 0 |
261 |
} |
262 |
|
263 |
################################################################################ |
264 |
# SPECIFIC FUNCTIONS # |
265 |
################################################################################ |
266 |
|
267 |
### print welcome text ######################################################### |
268 |
# Prints a welcome message to standard out. |
269 |
# |
270 |
# usage: printWelcomeText |
271 |
# arguments: n/a |
272 |
# return: n/a |
273 |
# |
274 |
function printWelcomeText { |
275 |
printf "######################################################################\n" |
276 |
printf "# #\n" |
277 |
printf "# Welcome to the QtCreator setup! #\n" |
278 |
printf "# #\n" |
279 |
printf "######################################################################\n" |
280 |
printf "# #\n" |
281 |
printf "# Copyright (c) 2016..2017 Thomas Schöpping #\n" |
282 |
printf "# #\n" |
283 |
printf "# This is free software; see the source for copying conditions. #\n" |
284 |
printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
285 |
printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
286 |
printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
287 |
printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
288 |
printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
289 |
printf "# Excellence Initiative. #\n" |
290 |
printf "# #\n" |
291 |
printf "######################################################################\n" |
292 |
} |
293 |
|
294 |
### print help ################################################################# |
295 |
# Prints a help text to standard out. |
296 |
# |
297 |
# usage: printHelp |
298 |
# arguments: n/a |
299 |
# return: n/a |
300 |
# |
301 |
function printHelp { |
302 |
printInfo "printing help text\n" |
303 |
printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [--LightRing] [--PowerManagement] [--DiWheelDrive] [-a|--all] [-q|--quit] [--log=<file>]\n" |
304 |
printf "\n" |
305 |
printf "options: -h, --help\n" |
306 |
printf " Print this help text.\n" |
307 |
printf " -c, --clean\n" |
308 |
printf " Delete project files.\n" |
309 |
printf " -w, --wipe\n" |
310 |
printf " Delete project and .user files.\n" |
311 |
printf " --LightRing\n" |
312 |
printf " Create project for the LightRing module.\n" |
313 |
printf " --PowerManagement\n" |
314 |
printf " Create project for the PowerManagement module.\n" |
315 |
printf " --DiWheelDrive\n" |
316 |
printf " Create project for the DiWheelDrive module.\n" |
317 |
printf " -a, --all\n" |
318 |
printf " Create projects for all modules.\n" |
319 |
printf " -q, --quit\n" |
320 |
printf " Quit the script.\n" |
321 |
printf " --log=<file>\n" |
322 |
printf " Specify a log file.\n" |
323 |
} |
324 |
|
325 |
### read directory where to create/delete projects ############################# |
326 |
# Read the directory where to create/delete project files from user. |
327 |
# |
328 |
# usage: getProjectDir <pathvar> |
329 |
# arguments: <pathvar> |
330 |
# Variable to store the selected path to. |
331 |
# return: n/a |
332 |
# |
333 |
function getProjectDir { |
334 |
printLog "reading path for project files from user...\n" |
335 |
local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../Target/) |
336 |
local input="" |
337 |
read -p "Path where to create/delete project files: " -i $amirobltdir -e input |
338 |
printLog "user selected path $(realpath $input)\n" |
339 |
eval $1="$(realpath $input)" |
340 |
} |
341 |
|
342 |
### retrieves the ARM-NONE-EABI-GCC include directory ########################## |
343 |
# Retrieves the include directory of the currently set arm-none-eabi-gcc. |
344 |
# |
345 |
# usage: retrieveGccIncludeDir <path> |
346 |
# arguments: <path> |
347 |
# Variable to store the path to. |
348 |
# return: 0 |
349 |
# No error or warning occurred. |
350 |
# -1 |
351 |
# Error: Command 'arm-none-eabi-gcc' not found. |
352 |
# |
353 |
function retrieveGccIncludeDir { |
354 |
# retrieve binary path or link |
355 |
local binpath=$(which arm-none-eabi-gcc) |
356 |
if [ -z "$binpath" ]; then |
357 |
printError "command 'arm-none-eabi-gcc' not found\n" |
358 |
return -1 |
359 |
else |
360 |
|
361 |
# traverse any links |
362 |
while [ -L "$binpath" ]; do |
363 |
binpath=$(readlink $binpath) |
364 |
done |
365 |
printInfo "gcc-arm-none-eabi detected: $binpath\n" |
366 |
|
367 |
# return include path |
368 |
eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/) |
369 |
|
370 |
return 0 |
371 |
fi |
372 |
} |
373 |
|
374 |
### delete project files ####################################################### |
375 |
# Deletes all project files and optionally .user files, too. |
376 |
# |
377 |
# usage: deleteProjects [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe] |
378 |
# arguments: -p, --path <path> |
379 |
# Path where to delete the project files. |
380 |
# -o, --out <var> |
381 |
# Variable to store the path to. |
382 |
# -w, --wipe |
383 |
# Delete .user files as well. |
384 |
# return: |
385 |
# - 0: no error |
386 |
# - 1: warning: function aborted by user |
387 |
# - -1: error: unexpected user input |
388 |
function deleteProjects { |
389 |
local projectdir="" |
390 |
local outvar="" |
391 |
local wipe=false |
392 |
|
393 |
# parse arguments |
394 |
local otherargs=() |
395 |
while [ $# -gt 0 ]; do |
396 |
if ( parseIsOption $1 ); then |
397 |
case "$1" in |
398 |
-p=*|--path=*) |
399 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
400 |
-p|--path) |
401 |
projectdir=$(realpath "$2"); shift 2;; |
402 |
-o=*|--out=*) |
403 |
outvar=${1#*=}; shift 1;; |
404 |
-o|--out) |
405 |
outvar=$2; shift 2;; |
406 |
-w|--wipe) |
407 |
wipe=true; shift 1;; |
408 |
*) |
409 |
printError "invalid option: $1\n"; shift 1;; |
410 |
esac |
411 |
else |
412 |
otherargs+=("$1") |
413 |
shift 1 |
414 |
fi |
415 |
done |
416 |
|
417 |
# print message |
418 |
if [ $wipe != true ]; then |
419 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n" |
420 |
else |
421 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n" |
422 |
fi |
423 |
|
424 |
# read project directory if required |
425 |
if [ -z "$projectdir" ]; then |
426 |
getProjectDir projectdir |
427 |
fi |
428 |
|
429 |
# remove all project files |
430 |
rm ${projectdir}/LightRing.includes 2>&1 | tee -a $LOG_FILE |
431 |
rm ${projectdir}/PowerManagement.includes 2>&1 | tee -a $LOG_FILE |
432 |
rm ${projectdir}/DiWheelDrive.includes 2>&1 | tee -a $LOG_FILE |
433 |
|
434 |
rm ${projectdir}/LightRing.files 2>&1 | tee -a $LOG_FILE |
435 |
rm ${projectdir}/PowerManagement.files 2>&1 | tee -a $LOG_FILE |
436 |
rm ${projectdir}/DiWheelDrive.files 2>&1 | tee -a $LOG_FILE |
437 |
|
438 |
rm ${projectdir}/LightRing.config 2>&1 | tee -a $LOG_FILE |
439 |
rm ${projectdir}/PowerManagement.config 2>&1 | tee -a $LOG_FILE |
440 |
rm ${projectdir}/DiWheelDrive.config 2>&1 | tee -a $LOG_FILE |
441 |
|
442 |
rm ${projectdir}/LightRing.creator 2>&1 | tee -a $LOG_FILE |
443 |
rm ${projectdir}/PowerManagement.creator 2>&1 | tee -a $LOG_FILE |
444 |
rm ${projectdir}/DiWheelDrive.creator 2>&1 | tee -a $LOG_FILE |
445 |
|
446 |
if [ $wipe == true ]; then |
447 |
rm ${projectdir}/LightRing.user 2>&1 | tee -a $LOG_FILE |
448 |
rm ${projectdir}/PowerManagement.user 2>&1 | tee -a $LOG_FILE |
449 |
rm ${projectdir}/DiWheelDrive.user 2>&1 | tee -a $LOG_FILE |
450 |
fi |
451 |
|
452 |
# store the path to the output variable, if required |
453 |
if [ ! -z "$outvar" ]; then |
454 |
eval $outvar="$projectdir" |
455 |
fi |
456 |
|
457 |
return 0 |
458 |
} |
459 |
|
460 |
### create LightRing project files ############################################# |
461 |
# Create project files for the LightRing module. |
462 |
# |
463 |
# usage: createLightRingProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
464 |
# arguments: -p, --path <path> |
465 |
# Path where to create the project files. |
466 |
# --gcc=<path> |
467 |
# Path to the GCC include directory. |
468 |
# -o, --out <var> |
469 |
# Variable to store the path to. |
470 |
# --gccout=<var> |
471 |
# Variable to store the path to the GCC include directory to. |
472 |
# return: 0 |
473 |
# No error or warning occurred. |
474 |
# |
475 |
function createLightRingProject { |
476 |
local projectdir="" |
477 |
local gccincludedir="" |
478 |
local outvar="" |
479 |
local gccoutvar="" |
480 |
|
481 |
# parse arguments |
482 |
local otherargs=() |
483 |
while [ $# -gt 0 ]; do |
484 |
if ( parseIsOption $1 ); then |
485 |
case "$1" in |
486 |
-p=*|--path=*) |
487 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
488 |
-p|--path) |
489 |
projectdir=$(realpath "$2"); shift 2;; |
490 |
--gcc=*) |
491 |
gccincludedir=$(realpath "${1#*=}"); shift 1;; |
492 |
--gcc) |
493 |
gccincludedir=$(realpath "$2"); shift 2;; |
494 |
-o=*|--out=*) |
495 |
outvar=${1#*=}; shift 1;; |
496 |
-o|--out) |
497 |
outvar=$2; shift 2;; |
498 |
--gccout=*) |
499 |
gccoutvar=$(realpath "${1#*=}"); shift 1;; |
500 |
--gccout) |
501 |
gccoutvar=$(realpath "$2"); shift 2;; |
502 |
*) |
503 |
printError "invalid option: $1\n"; shift 1;; |
504 |
esac |
505 |
else |
506 |
otherargs+=("$1") |
507 |
shift 1 |
508 |
fi |
509 |
done |
510 |
|
511 |
# print message |
512 |
printInfo "creating QtCreator project files for the LightRing module...\n" |
513 |
|
514 |
# read project directory if required |
515 |
if [ -z "$projectdir" ]; then |
516 |
getProjectDir projectdir |
517 |
fi |
518 |
|
519 |
# retrieve gcc-arm-none-eabi include dir |
520 |
if [ -z "$gccincludedir" ]; then |
521 |
retrieveGccIncludeDir gccincludedir |
522 |
fi |
523 |
|
524 |
# create project files |
525 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
526 |
find $gccincludedir -type d > ${projectdir}/LightRing.includes |
527 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/LightRing.includes |
528 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_LightRing_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/LightRing.includes |
529 |
# generate a file that specifies all files |
530 |
echo -n "" > ${projectdir}/LightRing.files |
531 |
for path in `cat ${projectdir}/LightRing.includes`; do |
532 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/LightRing.files |
533 |
done |
534 |
# generate a default project configuration file if none exists so far |
535 |
if [ ! -f ${projectdir}/LightRing.config ]; then |
536 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/LightRing.config |
537 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/LightRing.config |
538 |
echo -e "" >> ${projectdir}/LightRing.config |
539 |
fi |
540 |
# generate a default .creator file if none exists so far |
541 |
if [ ! -f ${projectdir}/LightRing.creator ]; then |
542 |
echo -e "[general]" > ${projectdir}/LightRing.creator |
543 |
echo -e "" >> ${projectdir}/LightRing.creator |
544 |
fi |
545 |
|
546 |
# fill the output variables |
547 |
if [ ! -z "$outvar" ]; then |
548 |
eval $outvar="$projectdir" |
549 |
fi |
550 |
if [ ! -z "$gccoutvar" ]; then |
551 |
eval $gccoutvar="$gccincludedir" |
552 |
fi |
553 |
|
554 |
return 0 |
555 |
} |
556 |
|
557 |
### create PowerManagement project files ####################################### |
558 |
# Create project files for the PowerManagement module. |
559 |
# |
560 |
# usage: createPowerManagementProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
561 |
# arguments: -p, --path <path> |
562 |
# Path where to create the project files. |
563 |
# --gcc=<path> |
564 |
# Path to the GCC include directory. |
565 |
# -o, --out <var> |
566 |
# Variable to store the path to. |
567 |
# --gccout=<var> |
568 |
# Variable to store the path to the GCC include directory to. |
569 |
# return: 0 |
570 |
# No error or warning occurred. |
571 |
# |
572 |
function createPowerManagementProject { |
573 |
local projectdir="" |
574 |
local gccincludedir="" |
575 |
local outvar="" |
576 |
local gccoutvar="" |
577 |
|
578 |
# parse arguments |
579 |
local otherargs=() |
580 |
while [ $# -gt 0 ]; do |
581 |
if ( parseIsOption $1 ); then |
582 |
case "$1" in |
583 |
-p=*|--path=*) |
584 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
585 |
-p|--path) |
586 |
projectdir=$(realpath "$2"); shift 2;; |
587 |
--gcc=*) |
588 |
gccincludedir=$(realpath "${1#*=}"); shift 1;; |
589 |
--gcc) |
590 |
gccincludedir=$(realpath "$2"); shift 2;; |
591 |
-o=*|--out=*) |
592 |
outvar=${1#*=}; shift 1;; |
593 |
-o|--out) |
594 |
outvar=$2; shift 2;; |
595 |
--gccout=*) |
596 |
gccoutvar=$(realpath "${1#*=}"); shift 1;; |
597 |
--gccout) |
598 |
gccoutvar=$(realpath "$2"); shift 2;; |
599 |
*) |
600 |
printError "invalid option: $1\n"; shift 1;; |
601 |
esac |
602 |
else |
603 |
otherargs+=("$1") |
604 |
shift 1 |
605 |
fi |
606 |
done |
607 |
|
608 |
# print message |
609 |
printInfo "creating QtCreator project files for the PowerManagement module...\n" |
610 |
|
611 |
# read project directory if required |
612 |
if [ -z "$projectdir" ]; then |
613 |
getProjectDir projectdir |
614 |
fi |
615 |
|
616 |
# retrieve gcc-arm-none-eabi include dir |
617 |
if [ -z "$gccincludedir" ]; then |
618 |
retrieveGccIncludeDir gccincludedir |
619 |
fi |
620 |
|
621 |
# create project files |
622 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
623 |
find $gccincludedir -type d > ${projectdir}/PowerManagement.includes |
624 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/PowerManagement.includes |
625 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM4_STM32F405_Power_Management_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/PowerManagement.includes |
626 |
# generate a file that specifies all files |
627 |
echo -n "" > ${projectdir}/PowerManagement.files |
628 |
for path in `cat ${projectdir}/PowerManagement.includes`; do |
629 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/PowerManagement.files |
630 |
done |
631 |
# generate a default project configuration file if none exists so far |
632 |
if [ ! -f ${projectdir}/PowerManagement.config ]; then |
633 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/PowerManagement.config |
634 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/PowerManagement.config |
635 |
echo -e "" >> ${projectdir}/PowerManagement.config |
636 |
fi |
637 |
# generate a default .creator file if none exists so far |
638 |
if [ ! -f ${projectdir}/PowerManagement.creator ]; then |
639 |
echo -e "[general]" > ${projectdir}/PowerManagement.creator |
640 |
echo -e "" >> ${projectdir}/PowerManagement.creator |
641 |
fi |
642 |
|
643 |
# fill the output variables |
644 |
if [ ! -z "$outvar" ]; then |
645 |
eval $outvar="$projectdir" |
646 |
fi |
647 |
if [ ! -z "$gccoutvar" ]; then |
648 |
eval $gccoutvar="$gccincludedir" |
649 |
fi |
650 |
|
651 |
return 0 |
652 |
} |
653 |
|
654 |
### create DiWheelDrive project files ########################################## |
655 |
# Create project files for the DiWheelDrive module. |
656 |
# |
657 |
# usage: createDiWheelDriveProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
658 |
# arguments: -p, --path <path> |
659 |
# Path where to create the project files. |
660 |
# --gcc=<path> |
661 |
# Path to the GCC include directory. |
662 |
# -o, --out <var> |
663 |
# Variable to store the path to. |
664 |
# --gccout=<var> |
665 |
# Variable to store the path to the GCC include directory to. |
666 |
# return: 0 |
667 |
# No error or warning occurred. |
668 |
# |
669 |
function createDiWheelDriveProject { |
670 |
local projectdir="" |
671 |
local gccincludedir="" |
672 |
local outvar="" |
673 |
local gccoutvar="" |
674 |
|
675 |
# parse arguments |
676 |
local otherargs=() |
677 |
while [ $# -gt 0 ]; do |
678 |
if ( parseIsOption $1 ); then |
679 |
case "$1" in |
680 |
-p=*|--path=*) |
681 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
682 |
-p|--path) |
683 |
projectdir=$(realpath "$2"); shift 2;; |
684 |
--gcc=*) |
685 |
gccincludedir=$(realpath "${1#*=}"); shift 1;; |
686 |
--gcc) |
687 |
gccincludedir=$(realpath "$2"); shift 2;; |
688 |
-o=*|--out=*) |
689 |
outvar=${1#*=}; shift 1;; |
690 |
-o|--out) |
691 |
outvar=$2; shift 2;; |
692 |
--gccout=*) |
693 |
gccoutvar=$(realpath "${1#*=}"); shift 1;; |
694 |
--gccout) |
695 |
gccoutvar=$(realpath "$2"); shift 2;; |
696 |
*) |
697 |
printError "invalid option: $1\n"; shift 1;; |
698 |
esac |
699 |
else |
700 |
otherargs+=("$1") |
701 |
shift 1 |
702 |
fi |
703 |
done |
704 |
|
705 |
# print message |
706 |
printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
707 |
|
708 |
# read project directory if required |
709 |
if [ -z "$projectdir" ]; then |
710 |
getProjectDir projectdir |
711 |
fi |
712 |
|
713 |
# retrieve gcc-arm-none-eabi include dir |
714 |
if [ -z "$gccincludedir" ]; then |
715 |
retrieveGccIncludeDir gccincludedir |
716 |
fi |
717 |
|
718 |
# create project files |
719 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
720 |
find $gccincludedir -type d > ${projectdir}/DiWheelDrive.includes |
721 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Source/) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/DiWheelDrive.includes |
722 |
find $(realpath $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_DiWheelDrive_GCC/Boot/) -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${projectdir}/DiWheelDrive.includes |
723 |
# generate a file that specifies all files |
724 |
echo -n "" > ${projectdir}/DiWheelDrive.files |
725 |
for path in `cat ${projectdir}/DiWheelDrive.includes`; do |
726 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/DiWheelDrive.files |
727 |
done |
728 |
# generate a default project configuration file if none exists so far |
729 |
if [ ! -f ${projectdir}/DiWheelDrive.config ]; then |
730 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/DiWheelDrive.config |
731 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/DiWheelDrive.config |
732 |
echo -e "" >> ${projectdir}/DiWheelDrive.config |
733 |
fi |
734 |
# generate a default .creator file if none exists so far |
735 |
if [ ! -f ${projectdir}/DiWheelDrive.creator ]; then |
736 |
echo -e "[general]" > ${projectdir}/DiWheelDrive.creator |
737 |
echo -e "" >> ${projectdir}/DiWheelDrive.creator |
738 |
fi |
739 |
|
740 |
# fill the output variables |
741 |
if [ ! -z "$outvar" ]; then |
742 |
eval $outvar="$projectdir" |
743 |
fi |
744 |
if [ ! -z "$gccoutvar" ]; then |
745 |
eval $gccoutvar="$gccincludedir" |
746 |
fi |
747 |
|
748 |
return 0 |
749 |
} |
750 |
|
751 |
### create project files for al modules ######################################## |
752 |
# Create project files for all modules. |
753 |
# |
754 |
# usage: createAllProjects |
755 |
# arguments: n/a |
756 |
# return: 0 |
757 |
# No error or warning occurred. |
758 |
# |
759 |
function createAllProjects { |
760 |
# print message |
761 |
printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
762 |
|
763 |
# read project directory |
764 |
local projectdir="" |
765 |
getProjectDir projectdir |
766 |
printInfo "files will be created in $projectdir\n" |
767 |
|
768 |
# retrieve gcc-arm-none-eabi include dir |
769 |
retrieveGccIncludeDir gccincludedir |
770 |
|
771 |
# create projects |
772 |
createLightRingProject --path="$projectdir" --gcc="$gccincludedir" |
773 |
createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir" |
774 |
createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir" |
775 |
|
776 |
return 0 |
777 |
} |
778 |
|
779 |
### main function of this script ############################################### |
780 |
# Creates, deletes and wipes QtCreator project files for the three AMiRo base modules. |
781 |
# |
782 |
# usage: see function printHelp |
783 |
# arguments: see function printHelp |
784 |
# return: 0 |
785 |
# No error or warning ocurred. |
786 |
# |
787 |
function main { |
788 |
# print welcome/info text if not suppressed |
789 |
if [[ $@ != *"--noinfo"* ]]; then |
790 |
printWelcomeText |
791 |
else |
792 |
printf "######################################################################\n" |
793 |
fi |
794 |
printf "\n" |
795 |
|
796 |
# if --help or -h was specified, print the help text and exit |
797 |
if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
798 |
printHelp |
799 |
printf "\n" |
800 |
quitScript |
801 |
fi |
802 |
|
803 |
# set log file if specified |
804 |
if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
805 |
# get the parameter (file name) |
806 |
local cmdidx=1 |
807 |
while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do |
808 |
cmdidx=$[cmdidx + 1] |
809 |
done |
810 |
local cmd="${!cmdidx}" |
811 |
local logfile="" |
812 |
if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
813 |
logfile=${cmd#*=} |
814 |
else |
815 |
local filenameidx=$((cmdidx + 1)) |
816 |
logfile="${!filenameidx}" |
817 |
fi |
818 |
# optionally force silent appending |
819 |
if [[ "$cmd" = "--LOG"* ]]; then |
820 |
setLogFile --option=a --quiet "$logfile" LOG_FILE |
821 |
else |
822 |
setLogFile "$logfile" LOG_FILE |
823 |
printf "\n" |
824 |
fi |
825 |
fi |
826 |
# log script name |
827 |
printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
828 |
|
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 |
863 |
done |
864 |
|
865 |
# interactive menu |
866 |
while ( true ); do |
867 |
# main menu info prompt and selection |
868 |
printInfo "QtCreator setup main menu\n" |
869 |
printf "Please select one of the following actions:\n" |
870 |
printf " [C] - clean project files\n" |
871 |
printf " [W] - wipe project and .user files\n" |
872 |
printf " [L] - create a project for the LightRing module\n" |
873 |
printf " [P] - create a project for the PowerManagement module\n" |
874 |
printf " [D] - create a project for the DiWheelDrive module\n" |
875 |
printf " [A] - create a project for all modules\n" |
876 |
printf " [Q] - quit this setup\n" |
877 |
local userinput="" |
878 |
readUserInput "CcWwLlPpDdAaQq" userinput |
879 |
printf "\n" |
880 |
|
881 |
# evaluate user selection |
882 |
case "$userinput" in |
883 |
C|c) |
884 |
deleteProjects; printf "\n";; |
885 |
W|w) |
886 |
deleteProjects --wipe; printf "\n";; |
887 |
L|l) |
888 |
createLightRingProject; printf "\n";; |
889 |
P|p) |
890 |
createPowerManagementProject; printf "\n";; |
891 |
D|d) |
892 |
createDiWheelDriveProject; printf "\n";; |
893 |
A|a) |
894 |
createAllProjects; printf "\n";; |
895 |
Q|q) |
896 |
quitScript;; |
897 |
*) # sanity check (exit with error) |
898 |
printError "unexpected argument: $userinput\n";; |
899 |
esac |
900 |
done |
901 |
|
902 |
exit 0 |
903 |
} |
904 |
|
905 |
################################################################################ |
906 |
# SCRIPT ENTRY POINT # |
907 |
################################################################################ |
908 |
|
909 |
main "$@" |
910 |
|