amiro-apps / tools / ide / QtCreator / QtCreatorSetup.sh @ 8dab1768
History | View | Annotate | Download (16.6 KB)
1 |
################################################################################ |
---|---|
2 |
# AMiRo-Apps is a collection of applications and configurations for the # |
3 |
# Autonomous Mini Robot (AMiRo). # |
4 |
# Copyright (C) 2018..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 |
# load library |
27 |
source "$(dirname ${BASH_SOURCE[0]})/../../bash/setuplib.sh" |
28 |
|
29 |
### print welcome text ######################################################### |
30 |
# Prints a welcome message to standard out. |
31 |
# |
32 |
# usage: printWelcomeText |
33 |
# arguments: n/a |
34 |
# return: n/a |
35 |
# |
36 |
function printWelcomeText { |
37 |
printf "######################################################################\n" |
38 |
printf "# #\n" |
39 |
printf "# Welcome to the QtCreator setup! #\n" |
40 |
printf "# #\n" |
41 |
printf "######################################################################\n" |
42 |
printf "# #\n" |
43 |
printf "# Copyright (c) 2018..2019 Thomas Schöpping #\n" |
44 |
printf "# #\n" |
45 |
printf "# This is free software; see the source for copying conditions. #\n" |
46 |
printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
47 |
printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
48 |
printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
49 |
printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
50 |
printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
51 |
printf "# Excellence Initiative. #\n" |
52 |
printf "# #\n" |
53 |
printf "######################################################################\n" |
54 |
} |
55 |
|
56 |
### print help ################################################################# |
57 |
# Prints a help text to standard out. |
58 |
# |
59 |
# usage: printHelp |
60 |
# arguments: n/a |
61 |
# return: n/a |
62 |
# |
63 |
function printHelp { |
64 |
printInfo "printing help text\n" |
65 |
printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [-q|--quit] [--log=<file>]\n" |
66 |
printf "\n" |
67 |
printf "options: -h, --help\n" |
68 |
printf " Print this help text.\n" |
69 |
printf " -i, --initialize\n" |
70 |
printf " Initialize project files.\n" |
71 |
printf " -c, --clean\n" |
72 |
printf " Delete project files.\n" |
73 |
printf " -w, --wipe\n" |
74 |
printf " Delete project and .user files.\n" |
75 |
printf " -q, --quit\n" |
76 |
printf " Quit the script.\n" |
77 |
printf " --log=<file>\n" |
78 |
printf " Specify a log file.\n" |
79 |
} |
80 |
|
81 |
### read directory where to create/delete projects ############################# |
82 |
# Read the directory where to create/delete project files from user. |
83 |
# |
84 |
# usage: getProjectDir <pathvar> |
85 |
# arguments: <pathvar> |
86 |
# Variable to store the selected path to. |
87 |
# return: n/a |
88 |
# |
89 |
function getProjectDir { |
90 |
printLog "reading path for project files from user...\n" |
91 |
local amiroappsdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../) |
92 |
local input="" |
93 |
read -p "Path where to create/delete project files: " -i $amiroappsdir -e input |
94 |
printLog "user selected path $(realpath $input)\n" |
95 |
eval $1="$(realpath $input)" |
96 |
} |
97 |
|
98 |
### retrieves the ARM-NONE-EABI-GCC include directory ########################## |
99 |
# Retrieves the include directory of the currently set arm-none-eabi-gcc. |
100 |
# |
101 |
# usage: retrieveGccIncludeDir <path> |
102 |
# arguments: <path> |
103 |
# Variable to store the path to. |
104 |
# return: 0 |
105 |
# No error or warning occurred. |
106 |
# -1 |
107 |
# Error: Command 'arm-none-eabi-gcc' not found. |
108 |
# |
109 |
function retrieveGccIncludeDir { |
110 |
# retrieve binary path or link |
111 |
local binpath=$(which arm-none-eabi-gcc) |
112 |
if [ -z "$binpath" ]; then |
113 |
printError "command 'arm-none-eabi-gcc' not found\n" |
114 |
return -1 |
115 |
else |
116 |
|
117 |
# traverse any links |
118 |
while [ -L "$binpath" ]; do |
119 |
binpath=$(readlink $binpath) |
120 |
done |
121 |
printInfo "gcc-arm-none-eabi detected: $binpath\n" |
122 |
|
123 |
# return include path |
124 |
eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/) |
125 |
|
126 |
return 0 |
127 |
fi |
128 |
} |
129 |
|
130 |
### intialize project files #################################################### |
131 |
# Initailizes all project files. |
132 |
# |
133 |
# usage: initProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
134 |
# arguments: -p, --path <path> |
135 |
# Path where to create the project files. |
136 |
# --gcc=<path> |
137 |
# Path to the GCC include directory. |
138 |
# -o, --out <var> |
139 |
# Variable to store the path to. |
140 |
# --gccout=<var> |
141 |
# Variable to store the path to the GCC include directory to. |
142 |
# return: 0 |
143 |
# No error or warning occurred. |
144 |
# |
145 |
function initProject { |
146 |
local userdir=$(pwd) |
147 |
local projectdir="" |
148 |
local gccincludedir="" |
149 |
local outvar="" |
150 |
local gccoutvar="" |
151 |
|
152 |
# parse arguments |
153 |
local otherargs=() |
154 |
while [ $# -gt 0 ]; do |
155 |
if ( parseIsOption $1 ); then |
156 |
case "$1" in |
157 |
-p=*|--path=*) |
158 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
159 |
-p|--path) |
160 |
projectdir=$(realpath "$2"); shift 2;; |
161 |
--gcc=*) |
162 |
gccincludedir=$(realpath "${1#*=}"); shift 1;; |
163 |
--gcc) |
164 |
gccincludedir=$(realpath "$2"); shift 2;; |
165 |
-o=*|--out=*) |
166 |
outvar=${1#*=}; shift 1;; |
167 |
-o|--out) |
168 |
outvar=$2; shift 2;; |
169 |
--gccout=*) |
170 |
gccoutvar=$(realpath "${1#*=}"); shift 1;; |
171 |
--gccout) |
172 |
gccoutvar=$(realpath "$2"); shift 2;; |
173 |
*) |
174 |
printError "invalid option: $1\n"; shift 1;; |
175 |
esac |
176 |
else |
177 |
otherargs+=("$1") |
178 |
shift 1 |
179 |
fi |
180 |
done |
181 |
|
182 |
# print message |
183 |
printInfo "creating QtCreator project files...\n" |
184 |
|
185 |
# read absolute project directory if required |
186 |
if [ -z "$projectdir" ]; then |
187 |
getProjectDir projectdir |
188 |
fi |
189 |
|
190 |
# retrieve absolute GCC include dir |
191 |
if [ -z "$gccincludedir" ]; then |
192 |
retrieveGccIncludeDir gccincludedir |
193 |
fi |
194 |
|
195 |
# move to project directory |
196 |
cd $projectdir |
197 |
|
198 |
# AMiRo-OS, ChibiOS, AMiRo-BLT, AMiRo-LLD and uRtWare relative root directories |
199 |
local amiroappsrootdir=$(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../..) |
200 |
local amiroosrootdir=$(realpath --relative-base=$projectdir ${amiroappsrootdir}/os/AMiRo-OS/os) |
201 |
local chibiosrootdir=$(realpath --relative-base=$projectdir ${amiroosrootdir}/../kernel/ChibiOS) |
202 |
local amirobltrootdir=$(realpath --relative-base=$projectdir ${amiroosrootdir}/../bootloader/AMiRo-BLT) |
203 |
local amirolldrootdir=$(realpath --relative-base=$projectdir ${amiroosrootdir}/../periphery-lld/AMiRo-LLD) |
204 |
local urtwarerootdir=$(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../../middleware/uRtWare/) |
205 |
|
206 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
207 |
find $gccincludedir -type d > ${projectdir}/AMiRo-Apps.includes |
208 |
find $amiroappsrootdir -type d | grep -E "/(apps|configurations)/.+" >> ${projectdir}/AMiRo-Apps.includes |
209 |
find $amiroosrootdir -type d | grep -v "/doc\|/build\|/.dep\|/hal\|/ports" >> ${projectdir}/AMiRo-Apps.includes |
210 |
find $amiroosrootdir -type d | grep -E "/os/hal/(include|src)" >> ${projectdir}/AMiRo-Apps.includes |
211 |
find $chibiosrootdir -type d | grep -E "/os/common/abstractions/cmsis_os$" >> ${projectdir}/AMiRo-Apps.includes |
212 |
find $chibiosrootdir -type d | grep -E "/os/common/oslib/(include|src)$" >> ${projectdir}/AMiRo-Apps.includes |
213 |
find $chibiosrootdir -type d | grep -E "/os/hal/(include|src)$" >> ${projectdir}/AMiRo-Apps.includes |
214 |
find $chibiosrootdir -type d | grep -E "/os/hal/lib/streams" >> ${projectdir}/AMiRo-Apps.includes |
215 |
find $chibiosrootdir -type d | grep -E "/os/hal/osal/(lib|rt)$" >> ${projectdir}/AMiRo-Apps.includes |
216 |
find $chibiosrootdir -type d | grep -E "/os/license$" >> ${projectdir}/AMiRo-Apps.includes |
217 |
find $chibiosrootdir -type d | grep -E "/os/rt/(include|src)$" >> ${projectdir}/AMiRo-Apps.includes |
218 |
find $chibiosrootdir -type d | grep -E "/os/various/(shell|cpp_wrappers)" >> ${projectdir}/AMiRo-Apps.includes |
219 |
find $chibiosrootdir -type d | grep -E "/test/(lib|rt/source/test)$" >> ${projectdir}/AMiRo-Apps.includes |
220 |
find $amirobltrootdir -type d | grep -E "/Target/Source/AMiRo$" >> ${projectdir}/AMiRo-Apps.includes |
221 |
echo "$(realpath --relative-base=$projectdir ${amirolldrootdir}/..)" >> ${projectdir}/AMiRo-Apps.includes |
222 |
find $amirolldrootdir -type d | grep -v "/doc" >> ${projectdir}/AMiRo-Apps.includes |
223 |
find $urtwarerootdir -type d | grep -v "/doc" >> ${projectdir}/AMiRo-Apps.includes |
224 |
# generate a file that specifies all files |
225 |
echo -n "" > ${projectdir}/AMiRo-Apps.files |
226 |
for path in `cat ${projectdir}/AMiRo-Apps.includes`; do |
227 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | |
228 |
grep -Ev "^.*/arm-none-eabi/.*$" | |
229 |
grep -E "^.*(\.s|\.S|\.h|\.c|\.hpp|\.cpp|\.tpp|\.ld)$" | |
230 |
grep -Ev "^${amirobltrootdir}/Target/Source/AMiRo/helper.*$" >> ${projectdir}/AMiRo-Apps.files; |
231 |
done |
232 |
# generate a default project configuration file if none exists so far |
233 |
if [ ! -f ${projectdir}/AMiRo-Apps.config ]; then |
234 |
echo "// Add predefined macros for your project here. For example:" > ${projectdir}/AMiRo-Apps.config |
235 |
echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/AMiRo-Apps.config |
236 |
fi |
237 |
# generate a default .creator file if none exists so far |
238 |
if [ ! -f ${projectdir}/AMiRo-Apps}.creator ]; then |
239 |
echo "[general]" > ${projectdir}/AMiRo-Apps.creator |
240 |
fi |
241 |
|
242 |
# go back to user directory |
243 |
cd $userdir |
244 |
|
245 |
# fill the output variables |
246 |
if [ ! -z "$outvar" ]; then |
247 |
eval $outvar="$projectdir" |
248 |
fi |
249 |
if [ ! -z "$gccoutvar" ]; then |
250 |
eval $gccoutvar="$gccincludedir" |
251 |
fi |
252 |
|
253 |
return 0 |
254 |
} |
255 |
|
256 |
### delete project files ####################################################### |
257 |
# Deletes all project files and optionally .user files, too. |
258 |
# |
259 |
# usage: deleteProject [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe] |
260 |
# arguments: -p, --path <path> |
261 |
# Path where to delete the project files. |
262 |
# -o, --out <var> |
263 |
# Variable to store the path to. |
264 |
# -w, --wipe |
265 |
# Delete .user files as well. |
266 |
# return: |
267 |
# - 0: no error |
268 |
# - 1: warning: function aborted by user |
269 |
# - -1: error: unexpected user input |
270 |
function deleteProject { |
271 |
local projectdir="" |
272 |
local outvar="" |
273 |
local wipe=false |
274 |
|
275 |
# parse arguments |
276 |
local otherargs=() |
277 |
while [ $# -gt 0 ]; do |
278 |
if ( parseIsOption $1 ); then |
279 |
case "$1" in |
280 |
-p=*|--path=*) |
281 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
282 |
-p|--path) |
283 |
projectdir=$(realpath "$2"); shift 2;; |
284 |
-o=*|--out=*) |
285 |
outvar=${1#*=}; shift 1;; |
286 |
-o|--out) |
287 |
outvar=$2; shift 2;; |
288 |
-w|--wipe) |
289 |
wipe=true; shift 1;; |
290 |
*) |
291 |
printError "invalid option: $1\n"; shift 1;; |
292 |
esac |
293 |
else |
294 |
otherargs+=("$1") |
295 |
shift 1 |
296 |
fi |
297 |
done |
298 |
|
299 |
# print message |
300 |
if [ $wipe != true ]; then |
301 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n" |
302 |
else |
303 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n" |
304 |
fi |
305 |
|
306 |
# read project directory if required |
307 |
if [ -z "$projectdir" ]; then |
308 |
getProjectDir projectdir |
309 |
fi |
310 |
|
311 |
# remove all project files |
312 |
rm ${projectdir}/AMiRo-Apps.includes 2>&1 | tee -a $LOG_FILE |
313 |
rm ${projectdir}/AMiRo-Apps.files 2>&1 | tee -a $LOG_FILE |
314 |
rm ${projectdir}/AMiRo-Apps.config 2>&1 | tee -a $LOG_FILE |
315 |
rm ${projectdir}/AMiRo-Apps.creator 2>&1 | tee -a $LOG_FILE |
316 |
|
317 |
if [ $wipe == true ]; then |
318 |
rm ${projectdir}/AMiRo-Apps.creator.user 2>&1 | tee -a $LOG_FILE |
319 |
fi |
320 |
|
321 |
# store the path to the output variable, if required |
322 |
if [ ! -z "$outvar" ]; then |
323 |
eval $outvar="$projectdir" |
324 |
fi |
325 |
|
326 |
return 0 |
327 |
|
328 |
} |
329 |
|
330 |
### main function of this script ############################################### |
331 |
# Creates, deletes and wipes QtCreator project files for the three AMiRo base modules. |
332 |
# |
333 |
# usage: see function printHelp |
334 |
# arguments: see function printHelp |
335 |
# return: 0 |
336 |
# No error or warning ocurred. |
337 |
# |
338 |
function main { |
339 |
# print welcome/info text if not suppressed |
340 |
if [[ $@ != *"--noinfo"* ]]; then |
341 |
printWelcomeText |
342 |
else |
343 |
printf "######################################################################\n" |
344 |
fi |
345 |
printf "\n" |
346 |
|
347 |
# if --help or -h was specified, print the help text and exit |
348 |
if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
349 |
printHelp |
350 |
printf "\n" |
351 |
quitScript |
352 |
fi |
353 |
|
354 |
# set log file if specified |
355 |
if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
356 |
# get the parameter (file name) |
357 |
local cmdidx=1 |
358 |
while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do |
359 |
cmdidx=$[cmdidx + 1] |
360 |
done |
361 |
local cmd="${!cmdidx}" |
362 |
local logfile="" |
363 |
if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
364 |
logfile=${cmd#*=} |
365 |
else |
366 |
local filenameidx=$((cmdidx + 1)) |
367 |
logfile="${!filenameidx}" |
368 |
fi |
369 |
# optionally force silent appending |
370 |
if [[ "$cmd" = "--LOG"* ]]; then |
371 |
setLogFile --option=c --quiet "$logfile" LOG_FILE |
372 |
else |
373 |
setLogFile "$logfile" LOG_FILE |
374 |
printf "\n" |
375 |
fi |
376 |
fi |
377 |
# log script name |
378 |
printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
379 |
|
380 |
# parse arguments |
381 |
local otherargs=() |
382 |
while [ $# -gt 0 ]; do |
383 |
if ( parseIsOption $1 ); then |
384 |
case "$1" in |
385 |
-h|--help) # already handled; ignore |
386 |
shift 1;; |
387 |
-c|--clean) |
388 |
deleteProjects; printf "\n"; shift 1;; |
389 |
-w|--wipe) |
390 |
deleteProjects --wipe; printf "\n"; shift 1;; |
391 |
-q|--quit) |
392 |
quitScript; shift 1;; |
393 |
--log=*|--LOG=*) # already handled; ignore |
394 |
shift 1;; |
395 |
--log|--LOG) # already handled; ignore |
396 |
shift 2;; |
397 |
--noinfo) # already handled; ignore |
398 |
shift 1;; |
399 |
*) |
400 |
printError "invalid option: $1\n"; shift 1;; |
401 |
esac |
402 |
else |
403 |
otherargs+=("$1") |
404 |
shift 1 |
405 |
fi |
406 |
done |
407 |
|
408 |
# interactive menu |
409 |
while ( true ); do |
410 |
# main menu info prompt and selection |
411 |
printInfo "QtCreator setup main menu\n" |
412 |
printf "Please select one of the following actions:\n" |
413 |
printf " [I] - initialize project files\n" |
414 |
printf " [C] - clean project files\n" |
415 |
printf " [W] - wipe project and .user files\n" |
416 |
printf " [Q] - quit this setup\n" |
417 |
local userinput="" |
418 |
readUserInput "IiCcWwQq" userinput |
419 |
printf "\n" |
420 |
|
421 |
# evaluate user selection |
422 |
case "$userinput" in |
423 |
I|i) |
424 |
initProject; printf "\n";; |
425 |
C|c) |
426 |
deleteProject; printf "\n";; |
427 |
W|w) |
428 |
deleteProject --wipe; printf "\n";; |
429 |
Q|q) |
430 |
quitScript;; |
431 |
*) # sanity check (exit with error) |
432 |
printError "unexpected argument: $userinput\n";; |
433 |
esac |
434 |
done |
435 |
|
436 |
exit 0 |
437 |
} |
438 |
|
439 |
################################################################################ |
440 |
# SCRIPT ENTRY POINT # |
441 |
################################################################################ |
442 |
|
443 |
main "$@" |