amiro-blt / tools / ide / QtCreator / QtCreatorSetup.sh @ 4745cc4c
History | View | Annotate | Download (34.381 KB)
1 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
---|---|---|---|
2 | 1da30dfc | Thomas Schöpping | # AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini # |
3 | # Robot (AMiRo) platform. # |
||
4 | 449d916a | Thomas Schöpping | # Copyright (C) 2016..2019 Thomas Schöpping et al. # |
5 | 4cce70a8 | Thomas Schöpping | # # |
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 | 69661903 | Thomas Schöpping | #!/bin/bash |
25 | |||
26 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
27 | 1da30dfc | Thomas Schöpping | # GENERIC FUNCTIONS # |
28 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
29 | 69661903 | Thomas Schöpping | |
30 | 0a42f078 | Thomas Schöpping | ### 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 | 1da30dfc | Thomas Schöpping | function printError { |
40 | local string="ERROR: $1" |
||
41 | # if a log file is specified |
||
42 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
43 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
44 | 69661903 | Thomas Schöpping | fi |
45 | 1da30dfc | Thomas Schöpping | printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2 |
46 | } |
||
47 | 69661903 | Thomas Schöpping | |
48 | 0a42f078 | Thomas Schöpping | ### 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 | 1da30dfc | Thomas Schöpping | function printWarning { |
58 | local string="WARNING: $1" |
||
59 | # if a log file is specified |
||
60 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
61 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
62 | fi |
||
63 | 0a42f078 | Thomas Schöpping | printf "$(tput setaf 3)>>> $string$(tput sgr 0)" |
64 | 1da30dfc | Thomas Schöpping | } |
65 | |||
66 | 0a42f078 | Thomas Schöpping | ### 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 | 1da30dfc | Thomas Schöpping | function printInfo { |
76 | local string="INFO: $1" |
||
77 | # if a log file is specified |
||
78 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
79 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
80 | fi |
||
81 | 0a42f078 | Thomas Schöpping | printf "$(tput setaf 2)>>> $string$(tput sgr 0)" |
82 | 1da30dfc | Thomas Schöpping | } |
83 | |||
84 | 0a42f078 | Thomas Schöpping | ### 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 | 1da30dfc | Thomas Schöpping | function printLog { |
93 | local string="LOG: $1" |
||
94 | # if a log file is specified |
||
95 | 0a42f078 | Thomas Schöpping | if [ -n "$LOG_FILE" ]; then |
96 | 1da30dfc | Thomas Schöpping | printf "[$(date '+%Y-%m-%d %H:%M:%S')] $string" >> $LOG_FILE |
97 | 69661903 | Thomas Schöpping | fi |
98 | 1da30dfc | Thomas Schöpping | } |
99 | |||
100 | 0a42f078 | Thomas Schöpping | ### 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 | 1da30dfc | Thomas Schöpping | function quitScript { |
109 | 3719a40a | Thomas Schöpping | printInfo "exiting $(realpath ${BASH_SOURCE[0]})\n" |
110 | printf "\n" |
||
111 | 1da30dfc | Thomas Schöpping | printf "######################################################################\n" |
112 | exit 0 |
||
113 | 69661903 | Thomas Schöpping | } |
114 | |||
115 | 0a42f078 | Thomas Schöpping | ### 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 | 1da30dfc | Thomas Schöpping | function readUserInput { |
128 | 0a42f078 | Thomas Schöpping | local input="" |
129 | 1da30dfc | Thomas Schöpping | # read user input |
130 | 0a42f078 | Thomas Schöpping | 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 | 69661903 | Thomas Schöpping | fi |
135 | done |
||
136 | 0a42f078 | Thomas Schöpping | printLog "[$input] has been selected\n" |
137 | eval $2="$input" |
||
138 | 1da30dfc | Thomas Schöpping | } |
139 | 69661903 | Thomas Schöpping | |
140 | 0a42f078 | Thomas Schöpping | ### 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 | 1da30dfc | Thomas Schöpping | return -1 |
160 | 69661903 | Thomas Schöpping | fi |
161 | 0a42f078 | Thomas Schöpping | } |
162 | 1da30dfc | Thomas Schöpping | |
163 | 0a42f078 | Thomas Schöpping | ### 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 | 0dc9f2f9 | Thomas Schöpping | # Possible values are 'a', 'c', 'r' and 'n'. |
173 | # - a: append (starts with a separator) |
||
174 | # - c: continue (does not insert a seperator) |
||
175 | 0a42f078 | Thomas Schöpping | # - 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 | 1da30dfc | Thomas Schöpping | local option="" |
192 | 0a42f078 | Thomas Schöpping | 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 | 1da30dfc | Thomas Schöpping | done |
213 | 0a42f078 | Thomas Schöpping | filepath=$(realpath ${otherargs[0]}) |
214 | 69661903 | Thomas Schöpping | |
215 | 1da30dfc | Thomas Schöpping | # if file already exists |
216 | 0a42f078 | Thomas Schöpping | if [ -e $filepath ]; then |
217 | 1da30dfc | Thomas Schöpping | # if no option was specified, ask what to do |
218 | 0a42f078 | Thomas Schöpping | if [ -z "$option" ]; then |
219 | printWarning "log file $filepath already esists\n" |
||
220 | local userinput="" |
||
221 | printf "Select what to do:\n" |
||
222 | 1da30dfc | Thomas Schöpping | printf " [A] - append log\n" |
223 | printf " [R] - restart log (delete existing file)\n" |
||
224 | printf " [N] - no log\n" |
||
225 | 0a42f078 | Thomas Schöpping | readUserInput "AaRrNn" userinput |
226 | 1da30dfc | Thomas Schöpping | option=${userinput,,} |
227 | fi |
||
228 | # evaluate option |
||
229 | 0a42f078 | Thomas Schöpping | case "$option" in |
230 | 0dc9f2f9 | Thomas Schöpping | a|c) |
231 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
232 | printInfo "appending log to $filepath\n" |
||
233 | fi |
||
234 | 0dc9f2f9 | Thomas Schöpping | if [ $option != c ]; then |
235 | printf "\n" >> $filepath |
||
236 | printf "######################################################################\n" >> $filepath |
||
237 | printf "\n" >> $filepath |
||
238 | fi |
||
239 | 1da30dfc | Thomas Schöpping | ;; |
240 | r) |
||
241 | 0a42f078 | Thomas Schöpping | echo -n "" > $filepath |
242 | if [ $quiet = false ]; then |
||
243 | printInfo "content of $filepath wiped\n" |
||
244 | fi |
||
245 | 1da30dfc | Thomas Schöpping | ;; |
246 | n) |
||
247 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
248 | printInfo "no log file will be generated\n" |
||
249 | fi |
||
250 | filepath="" |
||
251 | 1da30dfc | Thomas Schöpping | ;; |
252 | *) # sanity check (return error) |
||
253 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $option\n"; return -1;; |
254 | 1da30dfc | Thomas Schöpping | esac |
255 | 69661903 | Thomas Schöpping | else |
256 | 0a42f078 | Thomas Schöpping | if [ $quiet = false ]; then |
257 | printInfo "log file set to $filepath\n" |
||
258 | fi |
||
259 | 69661903 | Thomas Schöpping | fi |
260 | 0a42f078 | Thomas Schöpping | |
261 | eval ${otherargs[1]}="$filepath" |
||
262 | |||
263 | return 0 |
||
264 | 69661903 | Thomas Schöpping | } |
265 | 4cce70a8 | Thomas Schöpping | |
266 | fad4c1e7 | Thomas Schöpping | ### check whether commands are available ####################################### |
267 | # Checks whether the specified commands are available and can be executed. |
||
268 | # |
||
269 | e687187f | Thomas Schöpping | # usage: checkCommands [<command> <command> ...] |
270 | fad4c1e7 | Thomas Schöpping | # 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 | 1da30dfc | Thomas Schöpping | ################################################################################ |
301 | # SPECIFIC FUNCTIONS # |
||
302 | ################################################################################ |
||
303 | |||
304 | 0a42f078 | Thomas Schöpping | ### 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 | 1da30dfc | Thomas Schöpping | function printWelcomeText { |
312 | 4cce70a8 | Thomas Schöpping | printf "######################################################################\n" |
313 | printf "# #\n" |
||
314 | 1da30dfc | Thomas Schöpping | printf "# Welcome to the QtCreator setup! #\n" |
315 | 4cce70a8 | Thomas Schöpping | printf "# #\n" |
316 | printf "######################################################################\n" |
||
317 | printf "# #\n" |
||
318 | 449d916a | Thomas Schöpping | printf "# Copyright (c) 2016..2019 Thomas Schöpping #\n" |
319 | 4cce70a8 | Thomas Schöpping | 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 | 1da30dfc | Thomas Schöpping | } |
330 | |||
331 | 0a42f078 | Thomas Schöpping | ### print help ################################################################# |
332 | # Prints a help text to standard out. |
||
333 | # |
||
334 | # usage: printHelp |
||
335 | # arguments: n/a |
||
336 | # return: n/a |
||
337 | # |
||
338 | 1da30dfc | Thomas Schöpping | function printHelp { |
339 | printInfo "printing help text\n" |
||
340 | 6c75ad52 | Thomas Schöpping | printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [--module=<module>] [-a|--all] [-c|--clean] [-w|--wipe] [-q|--quit] [--log=<file>]\n" |
341 | 0a42f078 | Thomas Schöpping | printf "\n" |
342 | printf "options: -h, --help\n" |
||
343 | printf " Print this help text.\n" |
||
344 | 6c75ad52 | Thomas Schöpping | printf " --module=<module>\n" |
345 | printf " Create project for a single module.\n" |
||
346 | printf " -a, --all\n" |
||
347 | printf " Create projects for all modules.\n" |
||
348 | 0a42f078 | Thomas Schöpping | printf " -c, --clean\n" |
349 | printf " Delete project files.\n" |
||
350 | printf " -w, --wipe\n" |
||
351 | printf " Delete project and .user files.\n" |
||
352 | printf " -q, --quit\n" |
||
353 | printf " Quit the script.\n" |
||
354 | printf " --log=<file>\n" |
||
355 | printf " Specify a log file.\n" |
||
356 | 1da30dfc | Thomas Schöpping | } |
357 | 69661903 | Thomas Schöpping | |
358 | 0a42f078 | Thomas Schöpping | ### read directory where to create/delete projects ############################# |
359 | # Read the directory where to create/delete project files from user. |
||
360 | # |
||
361 | # usage: getProjectDir <pathvar> |
||
362 | # arguments: <pathvar> |
||
363 | # Variable to store the selected path to. |
||
364 | # return: n/a |
||
365 | # |
||
366 | 1da30dfc | Thomas Schöpping | function getProjectDir { |
367 | 0a42f078 | Thomas Schöpping | printLog "reading path for project files from user...\n" |
368 | 9085c3a0 | Thomas Schöpping | local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/) |
369 | 0a42f078 | Thomas Schöpping | local input="" |
370 | read -p "Path where to create/delete project files: " -i $amirobltdir -e input |
||
371 | printLog "user selected path $(realpath $input)\n" |
||
372 | eval $1="$(realpath $input)" |
||
373 | 1da30dfc | Thomas Schöpping | } |
374 | 69661903 | Thomas Schöpping | |
375 | 0a42f078 | Thomas Schöpping | ### retrieves the ARM-NONE-EABI-GCC include directory ########################## |
376 | # Retrieves the include directory of the currently set arm-none-eabi-gcc. |
||
377 | # |
||
378 | # usage: retrieveGccIncludeDir <path> |
||
379 | # arguments: <path> |
||
380 | # Variable to store the path to. |
||
381 | # return: 0 |
||
382 | # No error or warning occurred. |
||
383 | # -1 |
||
384 | # Error: Command 'arm-none-eabi-gcc' not found. |
||
385 | 6c75ad52 | Thomas Schöpping | # -2 |
386 | # Error: include directory could not be resolved |
||
387 | 0a42f078 | Thomas Schöpping | # |
388 | 1da30dfc | Thomas Schöpping | function retrieveGccIncludeDir { |
389 | # retrieve binary path or link |
||
390 | 0a42f078 | Thomas Schöpping | local binpath=$(which arm-none-eabi-gcc) |
391 | 6c75ad52 | Thomas Schöpping | local gccincpath="" |
392 | 1da30dfc | Thomas Schöpping | if [ -z "$binpath" ]; then |
393 | 0a42f078 | Thomas Schöpping | printError "command 'arm-none-eabi-gcc' not found\n" |
394 | 1da30dfc | Thomas Schöpping | return -1 |
395 | 0a42f078 | Thomas Schöpping | else |
396 | 69661903 | Thomas Schöpping | |
397 | 0a42f078 | Thomas Schöpping | # traverse any links |
398 | while [ -L "$binpath" ]; do |
||
399 | 7737db33 | Thomas Schöpping | binpath=$(realpath $(dirname $binpath)/$(readlink $binpath)) |
400 | 0a42f078 | Thomas Schöpping | done |
401 | printInfo "gcc-arm-none-eabi detected: $binpath\n" |
||
402 | 69661903 | Thomas Schöpping | |
403 | 0a42f078 | Thomas Schöpping | # return include path |
404 | 6c75ad52 | Thomas Schöpping | gccincpath=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/) |
405 | if [ ! -d "$gccincpath" ]; then |
||
406 | printWarning "$gccincpath does not exist\n" |
||
407 | return -2 |
||
408 | else |
||
409 | eval $1="$gccincpath" |
||
410 | return 0 |
||
411 | fi |
||
412 | 0a42f078 | Thomas Schöpping | fi |
413 | 1da30dfc | Thomas Schöpping | } |
414 | 69661903 | Thomas Schöpping | |
415 | 6c75ad52 | Thomas Schöpping | ### detect available modules ################################################### |
416 | # Detect all avalable modules supported by AMiRo-OS. |
||
417 | 0a42f078 | Thomas Schöpping | # |
418 | 6c75ad52 | Thomas Schöpping | # usage: detectModules <modulearray> |
419 | # arguments: <modulearray> |
||
420 | # Array variable to store all detected modules to. |
||
421 | # return: n/a |
||
422 | # |
||
423 | function detectModules { |
||
424 | local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/Modules) |
||
425 | local modules_detected=() |
||
426 | 69661903 | Thomas Schöpping | |
427 | 6c75ad52 | Thomas Schöpping | # detect all available modules (via directories) |
428 | for dir in $(ls -d ${modulesdir}/*/); do |
||
429 | modules_detected[${#modules_detected[@]}]=$(basename $dir) |
||
430 | 4cce70a8 | Thomas Schöpping | done |
431 | 69661903 | Thomas Schöpping | |
432 | 6c75ad52 | Thomas Schöpping | # set the output variable |
433 | eval "$1=(${modules_detected[*]})" |
||
434 | 1da30dfc | Thomas Schöpping | } |
435 | 4cce70a8 | Thomas Schöpping | |
436 | 6c75ad52 | Thomas Schöpping | ### create project files for a single module ################################### |
437 | # Create project files for a single module. |
||
438 | 0a42f078 | Thomas Schöpping | # |
439 | 6c75ad52 | Thomas Schöpping | # usage: createModuleProject <modules> [-m|--module=<module>] [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
440 | # arguments: <modules> |
||
441 | # Array containing all modules available. |
||
442 | # -m, --module <module> |
||
443 | # Name (folder name) of the module for which project files shall be generated. |
||
444 | # -p, --path <path> |
||
445 | 0a42f078 | Thomas Schöpping | # Path where to create the project files. |
446 | # --gcc=<path> |
||
447 | # Path to the GCC include directory. |
||
448 | # -o, --out <var> |
||
449 | # Variable to store the path to. |
||
450 | # --gccout=<var> |
||
451 | # Variable to store the path to the GCC include directory to. |
||
452 | 6c75ad52 | Thomas Schöpping | # If this optional arguments is absent, ths function will ask for user input. |
453 | 0a42f078 | Thomas Schöpping | # return: 0 |
454 | # No error or warning occurred. |
||
455 | 6c75ad52 | Thomas Schöpping | # 1 |
456 | # Aborted by user. |
||
457 | # -1 |
||
458 | # No modules available. |
||
459 | # -2 |
||
460 | # The specified <module> could not be found. |
||
461 | # -3 |
||
462 | # Parsing the project for the specified module failed. |
||
463 | # -4 |
||
464 | # Missing dependencies. |
||
465 | 0a42f078 | Thomas Schöpping | # |
466 | 6c75ad52 | Thomas Schöpping | function createModuleProject { |
467 | cc06d380 | Thomas Schöpping | local userdir=$(pwd) |
468 | 6c75ad52 | Thomas Schöpping | local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/Modules) |
469 | local modules=("${!1}") |
||
470 | local module="" |
||
471 | local moduleidx="" |
||
472 | 1da30dfc | Thomas Schöpping | local projectdir="" |
473 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
474 | 1da30dfc | Thomas Schöpping | local outvar="" |
475 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
476 | 4cce70a8 | Thomas Schöpping | |
477 | 6c75ad52 | Thomas Schöpping | # check dependencies |
478 | checkCommands make |
||
479 | if [ $? -ne 0 ]; then |
||
480 | printError "Missing dependencies detected.\n" |
||
481 | return -4 |
||
482 | fi |
||
483 | |||
484 | 0a42f078 | Thomas Schöpping | # parse arguments |
485 | local otherargs=() |
||
486 | while [ $# -gt 0 ]; do |
||
487 | if ( parseIsOption $1 ); then |
||
488 | case "$1" in |
||
489 | 6c75ad52 | Thomas Schöpping | -m=*|--module=*) |
490 | module="${1#*=}"; shift 1;; |
||
491 | -m|--module) |
||
492 | module="$2"; shift 2;; |
||
493 | 0a42f078 | Thomas Schöpping | -p=*|--path=*) |
494 | projectdir=$(realpath "${1#*=}"); shift 1;; |
||
495 | -p|--path) |
||
496 | projectdir=$(realpath "$2"); shift 2;; |
||
497 | --gcc=*) |
||
498 | gccincludedir=$(realpath "${1#*=}"); shift 1;; |
||
499 | --gcc) |
||
500 | gccincludedir=$(realpath "$2"); shift 2;; |
||
501 | -o=*|--out=*) |
||
502 | outvar=${1#*=}; shift 1;; |
||
503 | -o|--out) |
||
504 | outvar=$2; shift 2;; |
||
505 | --gccout=*) |
||
506 | gccoutvar=$(realpath "${1#*=}"); shift 1;; |
||
507 | --gccout) |
||
508 | gccoutvar=$(realpath "$2"); shift 2;; |
||
509 | *) |
||
510 | printError "invalid option: $1\n"; shift 1;; |
||
511 | esac |
||
512 | else |
||
513 | otherargs+=("$1") |
||
514 | shift 1 |
||
515 | fi |
||
516 | 1da30dfc | Thomas Schöpping | done |
517 | |||
518 | 6c75ad52 | Thomas Schöpping | # sanity check for the modules variable |
519 | if [ -z "${modules[*]}" ]; then |
||
520 | printError "no modules available\n" |
||
521 | return -1 |
||
522 | fi |
||
523 | |||
524 | # select module |
||
525 | if [ -z $module ]; then |
||
526 | # list all available modules |
||
527 | printInfo "choose a module or type 'A' to abort:\n" |
||
528 | for (( idx=0; idx<${#modules[@]}; ++idx )); do |
||
529 | printf "%4u: %s\n" $(($idx + 1)) "${modules[$idx]}" |
||
530 | done |
||
531 | # read user input |
||
532 | printLog "read user selection\n" |
||
533 | local userinput="" |
||
534 | while [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#modules[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; do |
||
535 | read -p "your selection: " -e userinput |
||
536 | printLog "user selection: $userinput\n" |
||
537 | if [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#modules[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; then |
||
538 | printWarning "Please enter an integer between 1 and ${#modules[@]} or 'A' to abort.\n" |
||
539 | fi |
||
540 | done |
||
541 | if [[ "$userinput" =~ ^[Aa]$ ]]; then |
||
542 | printWarning "aborted by user\n" |
||
543 | return 1 |
||
544 | fi |
||
545 | # store selection |
||
546 | moduleidx=$(($userinput - 1)) |
||
547 | module="${modules[$moduleidx]}" |
||
548 | printf "\n" |
||
549 | else |
||
550 | # search all modules for the selected one |
||
551 | for (( idx=0; idx<${#modules[@]}; ++idx )); do |
||
552 | if [ "${modules[$idx]}" = "$module" ]; then |
||
553 | moduleidx=$idx |
||
554 | break |
||
555 | fi |
||
556 | done |
||
557 | # error if the module could not be found |
||
558 | if [ -z $moduleidx ]; then |
||
559 | printError "module ($module) not available\n" |
||
560 | return -2 |
||
561 | fi |
||
562 | fi |
||
563 | 1da30dfc | Thomas Schöpping | |
564 | cc06d380 | Thomas Schöpping | # read absolute project directory if required |
565 | 1da30dfc | Thomas Schöpping | if [ -z "$projectdir" ]; then |
566 | getProjectDir projectdir |
||
567 | 6c75ad52 | Thomas Schöpping | printf "\n" |
568 | fi |
||
569 | |||
570 | # check for existing project files |
||
571 | local projectfiles="$(find ${projectdir} -maxdepth 1 -type f | grep -E "${module}\.(includes|files|config|creator)$")" |
||
572 | IFS=$'\n'; projectfiles=($projectfiles); unset IFS |
||
573 | if [ ! -z "${projectfiles[*]}" ]; then |
||
574 | printWarning "The following files will be overwritten:\n" |
||
575 | for pfile in ${projectfiles[@]}; do |
||
576 | printWarning "\t$(basename $pfile)\n" |
||
577 | done |
||
578 | local userinput="" |
||
579 | printInfo "Continue and overwrite? [y/n]\n" |
||
580 | readUserInput "YyNn" userinput |
||
581 | case "$userinput" in |
||
582 | Y|y) |
||
583 | ;; |
||
584 | N|n) |
||
585 | printWarning "Project generation for ${module} module aborted by user\n" |
||
586 | return 1 |
||
587 | ;; |
||
588 | *) |
||
589 | printError "unexpected input: ${userinput}\n"; return -999;; |
||
590 | esac |
||
591 | printf "\n" |
||
592 | 1da30dfc | Thomas Schöpping | fi |
593 | |||
594 | 6c75ad52 | Thomas Schöpping | # print message |
595 | printInfo "generating QtCreator project files for the $module module...\n" |
||
596 | |||
597 | # retrieve absolute GCC include path |
||
598 | 1da30dfc | Thomas Schöpping | if [ -z "$gccincludedir" ]; then |
599 | 0a42f078 | Thomas Schöpping | retrieveGccIncludeDir gccincludedir |
600 | 1da30dfc | Thomas Schöpping | fi |
601 | |||
602 | 6c75ad52 | Thomas Schöpping | # change to project directory |
603 | local amirobltrootdir=$(realpath $(dirname ${BASH_SOURCE[0]})/../../..) |
||
604 | cd "$projectdir" |
||
605 | |||
606 | # run make, but only run the GCC preprocessor and produce no binaries |
||
607 | local sourcefiles=() |
||
608 | local sourcefile="" |
||
609 | local parse_state="WAIT_FOR_INCLUDE_OR_COMPILE" |
||
610 | # capture all output from make and GCC and append the return value of make as last line |
||
611 | printInfo "processing project (this may take a while)...\n" |
||
612 | local rawout=$(make --directory ${amirobltrootdir}/Target/Modules/${module}/Boot --always-make USER_CFLAGS="-v -H" 2>&1 && echo $?) |
||
613 | # check whether the make call was successfull |
||
614 | if [[ $(echo "${rawout}" | tail -n 1) != "0" ]]; then |
||
615 | printError "executing 'make' in module directory failed\n" |
||
616 | cd "$userdir" |
||
617 | return -3 |
||
618 | fi |
||
619 | # extract file names from raw output |
||
620 | IFS=$'\n'; rawout=($rawout); unset IFS |
||
621 | for line in "${rawout[@]}"; do |
||
622 | case $parse_state in |
||
623 | WAIT_FOR_INCLUDE_OR_COMPILE) |
||
624 | # lines stating included files look like: |
||
625 | # ... <../relative/path/to/file> |
||
626 | if [[ "$line" =~ ^\.+[[:blank:]].+\..+$ ]]; then |
||
627 | sourcefile=${line##* } |
||
628 | if [[ ! "$sourcefile" =~ ^/ ]]; then |
||
629 | sourcefile=$(realpath ${amirobltrootdir}/Target/Modules/${module}/Boot/${sourcefile}) |
||
630 | fi |
||
631 | sourcefiles[${#sourcefiles[@]}]="$sourcefile" |
||
632 | # whenever the next source file is processed, a message appears like: |
||
633 | # Compining <filnemame> |
||
634 | elif [[ "$line" =~ ^\+\+\+[[:blank:]]Compiling[[:blank:]]\[(.+\.c)\]$ ]]; then |
||
635 | printf "." |
||
636 | sourcefile=${BASH_REMATCH[1]} |
||
637 | parse_state="WAIT_FOR_COMPILERCALL" |
||
638 | fi;; |
||
639 | WAIT_FOR_COMPILERCALL) |
||
640 | # wait for the actual call of the compiler to retrieve the full path to the source file |
||
641 | if [[ "$line" == *${sourcefile}* ]]; then |
||
642 | line="${line%%${sourcefile}*}${sourcefile}" |
||
643 | sourcefile=$(realpath ${amirobltrootdir}/Target/Modules/${module}/Boot/${line##* }) |
||
644 | sourcefiles[${#sourcefiles[@]}]="$sourcefile" |
||
645 | parse_state="WAIT_FOR_INCLUDE_OR_COMPILE" |
||
646 | fi;; |
||
647 | esac |
||
648 | done |
||
649 | unset rawout |
||
650 | printf "\n" |
||
651 | # sort and remove duplicates |
||
652 | IFS=$'\n'; sourcefiles=($(sort --unique <<< "${sourcefiles[*]}")); unset IFS |
||
653 | |||
654 | # extract include paths |
||
655 | local includes=() |
||
656 | for source in ${sourcefiles[*]}; do |
||
657 | includes[${#includes[@]}]="$(dirname ${source})" |
||
658 | done |
||
659 | # sort and remove duplicates |
||
660 | IFS=$'\n'; includes=($(sort --unique <<< "${includes[*]}")); unset IFS |
||
661 | |||
662 | # generate the .files file, containing all source files |
||
663 | echo "" > ${projectdir}/${module}.includes |
||
664 | for inc in ${includes[*]}; do |
||
665 | echo "$inc" >> ${projectdir}/${module}.includes |
||
666 | 1da30dfc | Thomas Schöpping | done |
667 | 6c75ad52 | Thomas Schöpping | # generate the .incldues file, containing all include paths |
668 | echo "" > ${projectdir}/${module}.files |
||
669 | for source in ${sourcefiles[*]}; do |
||
670 | # skip GCC files |
||
671 | if [[ ! "$source" =~ .*/gcc.* ]]; then |
||
672 | echo "$source" >> ${projectdir}/${module}.files |
||
673 | fi |
||
674 | done |
||
675 | # generate a default project configuration file if it doesn't exist yet |
||
676 | if [ ! -f ${projectdir}/${module}.config ]; then |
||
677 | echo "// Add predefined macros for your project here. For example:" > ${projectdir}/${module}.config |
||
678 | echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/${module}.config |
||
679 | 1da30dfc | Thomas Schöpping | fi |
680 | 6c75ad52 | Thomas Schöpping | # generate a default .creator file if it doesn't exist yet |
681 | if [ ! -f ${projectdir}/${module}.creator ]; then |
||
682 | echo "[general]" > ${projectdir}/${module}.creator |
||
683 | 1da30dfc | Thomas Schöpping | fi |
684 | |||
685 | cc06d380 | Thomas Schöpping | # go back to user directory |
686 | cd $userdir |
||
687 | |||
688 | 0a42f078 | Thomas Schöpping | # fill the output variables |
689 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
690 | eval $outvar="$projectdir" |
||
691 | fi |
||
692 | 0a42f078 | Thomas Schöpping | if [ ! -z "$gccoutvar" ]; then |
693 | eval $gccoutvar="$gccincludedir" |
||
694 | fi |
||
695 | 4cce70a8 | Thomas Schöpping | |
696 | 1da30dfc | Thomas Schöpping | return 0 |
697 | } |
||
698 | 4cce70a8 | Thomas Schöpping | |
699 | 6c75ad52 | Thomas Schöpping | ### create project files for all modules ####################################### |
700 | # Create project files for all modules. |
||
701 | 0a42f078 | Thomas Schöpping | # |
702 | 6c75ad52 | Thomas Schöpping | # usage: createAllProjects <modules> [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
703 | # arguments: <modules> |
||
704 | # Array containing all modules available. |
||
705 | # -p, --path <path> |
||
706 | 0a42f078 | Thomas Schöpping | # Path where to create the project files. |
707 | # --gcc=<path> |
||
708 | # Path to the GCC include directory. |
||
709 | # -o, --out <var> |
||
710 | # Variable to store the path to. |
||
711 | # --gccout=<var> |
||
712 | # Variable to store the path to the GCC include directory to. |
||
713 | 6c75ad52 | Thomas Schöpping | # If this optional arguments is absent, ths function will ask for user input. |
714 | 0a42f078 | Thomas Schöpping | # return: 0 |
715 | # No error or warning occurred. |
||
716 | 6c75ad52 | Thomas Schöpping | # 1 |
717 | # Aborted by user. |
||
718 | # -1 |
||
719 | # No modules available. |
||
720 | 0a42f078 | Thomas Schöpping | # |
721 | 6c75ad52 | Thomas Schöpping | function createAllProjects { |
722 | local modules=("${!1}") |
||
723 | 1da30dfc | Thomas Schöpping | local projectdir="" |
724 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
725 | 1da30dfc | Thomas Schöpping | local outvar="" |
726 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
727 | 4cce70a8 | Thomas Schöpping | |
728 | 0a42f078 | Thomas Schöpping | # 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 | 1da30dfc | Thomas Schöpping | done |
757 | |||
758 | 6c75ad52 | Thomas Schöpping | # sanity check for the modules variable |
759 | if [ -z "${modules[*]}" ]; then |
||
760 | printError "no modules available\n" |
||
761 | return -1 |
||
762 | fi |
||
763 | 4cce70a8 | Thomas Schöpping | |
764 | cc06d380 | Thomas Schöpping | # read absolute project directory if required |
765 | 1da30dfc | Thomas Schöpping | if [ -z "$projectdir" ]; then |
766 | getProjectDir projectdir |
||
767 | fi |
||
768 | |||
769 | 6c75ad52 | Thomas Schöpping | # check for existing project files |
770 | local projectfiles=() |
||
771 | for module in ${modules[@]}; do |
||
772 | local pfiles="$(find ${projectdir} -maxdepth 1 -type f | grep -E "${module}\.(includes|files|config|creator)$")" |
||
773 | IFS=$'\n'; pfiles=($pfiles); unset IFS |
||
774 | projectfiles=( ${projectfiles[*]} ${pfiles[*]} ) |
||
775 | 1da30dfc | Thomas Schöpping | done |
776 | 6c75ad52 | Thomas Schöpping | if [ ! -z "${projectfiles[*]}" ]; then |
777 | printWarning "The following files will be removed:\n" |
||
778 | for pfile in ${projectfiles[@]}; do |
||
779 | printWarning "\t$(basename $pfile)\n" |
||
780 | done |
||
781 | local userinput="" |
||
782 | printInfo "Continue and overwrite? [y/n]\n" |
||
783 | readUserInput "YyNn" userinput |
||
784 | case "${userinput}" in |
||
785 | Y|y) |
||
786 | for pfile in ${projectfiles[*]}; do |
||
787 | rm "$pfile" |
||
788 | done |
||
789 | ;; |
||
790 | N|n) |
||
791 | printWarning "Project generation aborted by user\n" |
||
792 | return 1 |
||
793 | ;; |
||
794 | *) |
||
795 | printError "unexpected input: ${userinput}\n" |
||
796 | return 999 |
||
797 | ;; |
||
798 | esac |
||
799 | 1da30dfc | Thomas Schöpping | fi |
800 | 4cce70a8 | Thomas Schöpping | |
801 | 6c75ad52 | Thomas Schöpping | # print message |
802 | printf "\n" |
||
803 | printInfo "generating QtCreator project files for all modules...\n" |
||
804 | cc06d380 | Thomas Schöpping | |
805 | 6c75ad52 | Thomas Schöpping | # retrieve absolute GCC include path |
806 | if [ -z "$gccincludedir" ]; then |
||
807 | retrieveGccIncludeDir gccincludedir |
||
808 | 0a42f078 | Thomas Schöpping | fi |
809 | 4cce70a8 | Thomas Schöpping | |
810 | 6c75ad52 | Thomas Schöpping | # iterate over all modules |
811 | local retval=1 |
||
812 | for module in ${modules[@]}; do |
||
813 | if [ $retval != 0 ]; then |
||
814 | printf "\n" |
||
815 | fi |
||
816 | createModuleProject modules[@] --module="$module" --path="$projectdir" --gcc="$gccincludedir" |
||
817 | retval=$? |
||
818 | done |
||
819 | |||
820 | 1da30dfc | Thomas Schöpping | return 0 |
821 | } |
||
822 | 4cce70a8 | Thomas Schöpping | |
823 | 6c75ad52 | Thomas Schöpping | ### delete project files ####################################################### |
824 | # Deletes all project files and optionally .user files, too. |
||
825 | 0a42f078 | Thomas Schöpping | # |
826 | 6c75ad52 | Thomas Schöpping | # usage: deleteProjects [-p|--path=<path>] [-m|--module=<module>] [-o|--out=<var>] [-w|-wipe] |
827 | 0a42f078 | Thomas Schöpping | # arguments: -p, --path <path> |
828 | 6c75ad52 | Thomas Schöpping | # Path where to delete the project files. |
829 | # -m, --module <module> |
||
830 | # Module name for which the project files shall be deleted. |
||
831 | 0a42f078 | Thomas Schöpping | # -o, --out <var> |
832 | # Variable to store the path to. |
||
833 | 6c75ad52 | Thomas Schöpping | # -w, --wipe |
834 | # Delete .user files as well. |
||
835 | # return: |
||
836 | # - 0: no error |
||
837 | 0a42f078 | Thomas Schöpping | # |
838 | 6c75ad52 | Thomas Schöpping | function deleteProjects { |
839 | local modulename="" |
||
840 | 1da30dfc | Thomas Schöpping | local projectdir="" |
841 | local outvar="" |
||
842 | 6c75ad52 | Thomas Schöpping | local wipe=false |
843 | local files="" |
||
844 | 4cce70a8 | Thomas Schöpping | |
845 | 0a42f078 | Thomas Schöpping | # parse arguments |
846 | local otherargs=() |
||
847 | while [ $# -gt 0 ]; do |
||
848 | if ( parseIsOption $1 ); then |
||
849 | case "$1" in |
||
850 | -p=*|--path=*) |
||
851 | projectdir=$(realpath "${1#*=}"); shift 1;; |
||
852 | -p|--path) |
||
853 | projectdir=$(realpath "$2"); shift 2;; |
||
854 | 6c75ad52 | Thomas Schöpping | -m=*|--module=*) |
855 | modulename="${1#*=}"; shift 1;; |
||
856 | -m|--module) |
||
857 | modulename="${2}"; shift 2;; |
||
858 | 0a42f078 | Thomas Schöpping | -o=*|--out=*) |
859 | outvar=${1#*=}; shift 1;; |
||
860 | -o|--out) |
||
861 | outvar=$2; shift 2;; |
||
862 | 6c75ad52 | Thomas Schöpping | -w|--wipe) |
863 | wipe=true; shift 1;; |
||
864 | 0a42f078 | Thomas Schöpping | *) |
865 | printError "invalid option: $1\n"; shift 1;; |
||
866 | esac |
||
867 | else |
||
868 | otherargs+=("$1") |
||
869 | shift 1 |
||
870 | fi |
||
871 | 1da30dfc | Thomas Schöpping | done |
872 | 4cce70a8 | Thomas Schöpping | |
873 | cc06d380 | Thomas Schöpping | # read absolute project directory if required |
874 | 1da30dfc | Thomas Schöpping | if [ -z "$projectdir" ]; then |
875 | getProjectDir projectdir |
||
876 | fi |
||
877 | 4cce70a8 | Thomas Schöpping | |
878 | 6c75ad52 | Thomas Schöpping | # list all files to be deleted |
879 | if [ -z "$modulename" ]; then |
||
880 | if [ $wipe != true ]; then |
||
881 | files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator|cflags|cxxflags)$") |
||
882 | else |
||
883 | files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator|cflags|cxxflags|creator(\.user(\..+)?)?)$") |
||
884 | fi |
||
885 | else |
||
886 | if [ $wipe != true ]; then |
||
887 | files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^${modulename}\.(includes|files|config|creator|cflags|cxxflags)$") |
||
888 | else |
||
889 | files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^${modulename}\.(includes|files|config|creator|cflags|cxxflags|creator(\.user(\..+)?)?)$") |
||
890 | fi |
||
891 | 1da30dfc | Thomas Schöpping | fi |
892 | 6c75ad52 | Thomas Schöpping | if [ ! -z "$files" ]; then |
893 | printInfo "Deleting the following files:\n" |
||
894 | while read line; do |
||
895 | printInfo "\t$(basename ${line})\n" |
||
896 | rm ${line} 2>&1 | tee -a $LOG_FILE |
||
897 | done <<< "${files}" |
||
898 | else |
||
899 | printInfo "No project files found\n" |
||
900 | 1da30dfc | Thomas Schöpping | fi |
901 | 4cce70a8 | Thomas Schöpping | |
902 | 6c75ad52 | Thomas Schöpping | # store the path to the output variable, if required |
903 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
904 | eval $outvar="$projectdir" |
||
905 | fi |
||
906 | 4cce70a8 | Thomas Schöpping | |
907 | 1da30dfc | Thomas Schöpping | return 0 |
908 | } |
||
909 | 4cce70a8 | Thomas Schöpping | |
910 | 0a42f078 | Thomas Schöpping | ### main function of this script ############################################### |
911 | # Creates, deletes and wipes QtCreator project files for the three AMiRo base modules. |
||
912 | # |
||
913 | # usage: see function printHelp |
||
914 | # arguments: see function printHelp |
||
915 | # return: 0 |
||
916 | # No error or warning ocurred. |
||
917 | # |
||
918 | 1da30dfc | Thomas Schöpping | function main { |
919 | 0a42f078 | Thomas Schöpping | # print welcome/info text if not suppressed |
920 | 1da30dfc | Thomas Schöpping | if [[ $@ != *"--noinfo"* ]]; then |
921 | printWelcomeText |
||
922 | else |
||
923 | printf "######################################################################\n" |
||
924 | fi |
||
925 | printf "\n" |
||
926 | |||
927 | 1446566f | Thomas Schöpping | # if --help or -h was specified, print the help text and exit |
928 | if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
||
929 | printHelp |
||
930 | printf "\n" |
||
931 | quitScript |
||
932 | fi |
||
933 | |||
934 | 1da30dfc | Thomas Schöpping | # set log file if specified |
935 | 0a42f078 | Thomas Schöpping | if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
936 | 1da30dfc | Thomas Schöpping | # get the parameter (file name) |
937 | local cmdidx=1 |
||
938 | 0a42f078 | Thomas Schöpping | while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do |
939 | 1da30dfc | Thomas Schöpping | cmdidx=$[cmdidx + 1] |
940 | done |
||
941 | 0a42f078 | Thomas Schöpping | local cmd="${!cmdidx}" |
942 | local logfile="" |
||
943 | if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
||
944 | logfile=${cmd#*=} |
||
945 | else |
||
946 | local filenameidx=$((cmdidx + 1)) |
||
947 | logfile="${!filenameidx}" |
||
948 | fi |
||
949 | 1da30dfc | Thomas Schöpping | # optionally force silent appending |
950 | 0a42f078 | Thomas Schöpping | if [[ "$cmd" = "--LOG"* ]]; then |
951 | 0dc9f2f9 | Thomas Schöpping | setLogFile --option=c --quiet "$logfile" LOG_FILE |
952 | 1da30dfc | Thomas Schöpping | else |
953 | 0a42f078 | Thomas Schöpping | setLogFile "$logfile" LOG_FILE |
954 | 1da30dfc | Thomas Schöpping | printf "\n" |
955 | fi |
||
956 | fi |
||
957 | # log script name |
||
958 | printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
||
959 | 4cce70a8 | Thomas Schöpping | |
960 | 6c75ad52 | Thomas Schöpping | # detect available modules and inform user |
961 | local modules=() |
||
962 | detectModules modules |
||
963 | case "${#modules[@]}" in |
||
964 | 0) |
||
965 | printInfo "no module has been detected\n";; |
||
966 | 1) |
||
967 | printInfo "1 module has been detected:\n";; |
||
968 | *) |
||
969 | printInfo "${#modules[@]} modules have been detected:\n" |
||
970 | esac |
||
971 | for (( idx=0; idx<${#modules[@]}; ++idx )); do |
||
972 | printInfo " - ${modules[$idx]}\n" |
||
973 | done |
||
974 | printf "\n" |
||
975 | |||
976 | 0a42f078 | Thomas Schöpping | # parse arguments |
977 | local otherargs=() |
||
978 | while [ $# -gt 0 ]; do |
||
979 | if ( parseIsOption $1 ); then |
||
980 | case "$1" in |
||
981 | -h|--help) # already handled; ignore |
||
982 | shift 1;; |
||
983 | 6c75ad52 | Thomas Schöpping | -m=*|--module=*) |
984 | createModuleProject modules[@] --module="${1#*=}"; printf "\n"; shift 1;; |
||
985 | -m|--module) |
||
986 | createModuleProject modules[@] --module="${2}"; printf "\n"; shift 2;; |
||
987 | -a|--all) |
||
988 | createAllProjects modules[@]; shift 1;; |
||
989 | 0a42f078 | Thomas Schöpping | -c|--clean) |
990 | deleteProjects; printf "\n"; shift 1;; |
||
991 | -w|--wipe) |
||
992 | deleteProjects --wipe; printf "\n"; shift 1;; |
||
993 | -q|--quit) |
||
994 | quitScript; shift 1;; |
||
995 | --log=*|--LOG=*) # already handled; ignore |
||
996 | shift 1;; |
||
997 | --log|--LOG) # already handled; ignore |
||
998 | shift 2;; |
||
999 | --noinfo) # already handled; ignore |
||
1000 | shift 1;; |
||
1001 | *) |
||
1002 | printError "invalid option: $1\n"; shift 1;; |
||
1003 | esac |
||
1004 | else |
||
1005 | otherargs+=("$1") |
||
1006 | shift 1 |
||
1007 | fi |
||
1008 | 1da30dfc | Thomas Schöpping | done |
1009 | 4cce70a8 | Thomas Schöpping | |
1010 | 6c75ad52 | Thomas Schöpping | # interactive menu |
1011 | 0a42f078 | Thomas Schöpping | while ( true ); do |
1012 | 1da30dfc | Thomas Schöpping | # main menu info prompt and selection |
1013 | printInfo "QtCreator setup main menu\n" |
||
1014 | printf "Please select one of the following actions:\n" |
||
1015 | 6c75ad52 | Thomas Schöpping | printf " [M] - create a project for a single module\n" |
1016 | 1da30dfc | Thomas Schöpping | printf " [A] - create a project for all modules\n" |
1017 | 6c75ad52 | Thomas Schöpping | printf " [C] - clean all project files\n" |
1018 | printf " [W] - wipe all project and .user files\n" |
||
1019 | 1da30dfc | Thomas Schöpping | printf " [Q] - quit this setup\n" |
1020 | 0a42f078 | Thomas Schöpping | local userinput="" |
1021 | 6c75ad52 | Thomas Schöpping | readUserInput "MmAaCcWwQq" userinput |
1022 | 1da30dfc | Thomas Schöpping | printf "\n" |
1023 | |||
1024 | # evaluate user selection |
||
1025 | 0a42f078 | Thomas Schöpping | case "$userinput" in |
1026 | 6c75ad52 | Thomas Schöpping | M|m) |
1027 | createModuleProject modules[@]; printf "\n";; |
||
1028 | A|a) |
||
1029 | createAllProjects modules[@]; printf "\n";; |
||
1030 | 1da30dfc | Thomas Schöpping | C|c) |
1031 | 0a42f078 | Thomas Schöpping | deleteProjects; printf "\n";; |
1032 | 1da30dfc | Thomas Schöpping | W|w) |
1033 | 0a42f078 | Thomas Schöpping | deleteProjects --wipe; printf "\n";; |
1034 | 1da30dfc | Thomas Schöpping | Q|q) |
1035 | 0a42f078 | Thomas Schöpping | quitScript;; |
1036 | 1da30dfc | Thomas Schöpping | *) # sanity check (exit with error) |
1037 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $userinput\n";; |
1038 | 4cce70a8 | Thomas Schöpping | esac |
1039 | done |
||
1040 | 1da30dfc | Thomas Schöpping | |
1041 | exit 0 |
||
1042 | } |
||
1043 | 69661903 | Thomas Schöpping | |
1044 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
1045 | 1da30dfc | Thomas Schöpping | # SCRIPT ENTRY POINT # |
1046 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
1047 | 69661903 | Thomas Schöpping | |
1048 | 1da30dfc | Thomas Schöpping | main "$@" |