Revision 6feb42c8 ide/QtCreator/QtCreatorSetup.sh
ide/QtCreator/QtCreatorSetup.sh | ||
---|---|---|
1 | 1 |
################################################################################ |
2 |
# AMiRo-OS is an operating system designed for the Autonomous Mini Robot #
|
|
3 |
# (AMiRo) platform. #
|
|
4 |
# Copyright (C) 2016..2017 Thomas Schöpping et al. #
|
|
2 |
# AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini #
|
|
3 |
# Robot (AMiRo) platform. #
|
|
4 |
# Copyright (C) 2016..2018 Thomas Schöpping et al. #
|
|
5 | 5 |
# # |
6 | 6 |
# This program is free software: you can redistribute it and/or modify # |
7 | 7 |
# it under the terms of the GNU General Public License as published by # |
... | ... | |
24 | 24 |
#!/bin/bash |
25 | 25 |
|
26 | 26 |
################################################################################ |
27 |
### HELPER FUNCTIONS ###
|
|
27 |
# GENERIC FUNCTIONS #
|
|
28 | 28 |
################################################################################ |
29 | 29 |
|
30 |
#------------------------------------------------------------------------------- |
|
31 |
# toAbsolutePath $1 [$2] |
|
32 |
# |
|
33 |
# Makes a given path absolute and either echos the result or stores it in the |
|
34 |
# specified variable. |
|
35 |
# arguments: |
|
36 |
# $1: the path to be converted |
|
37 |
# $2: a variable to store the resulting path [optiional] |
|
38 |
function toAbsolutePath { |
|
39 |
# the path that shall be converted if required |
|
40 |
TARGET_PATH=$1 |
|
41 |
|
|
42 |
# store the path where the script was called from |
|
43 |
ORIGIN_PATH="${PWD}/" |
|
44 |
|
|
45 |
# check, whether the target is a directory or not |
|
46 |
if [ -d $TARGET_PATH ]; then |
|
47 |
cd $TARGET_PATH |
|
48 |
# special case: the target is the root directory |
|
49 |
if [ $TARGET_PATH = "/" ]; then |
|
50 |
ABSOLUTE_PATH="${PWD}" |
|
51 |
else |
|
52 |
ABSOLUTE_PATH="${PWD}/" |
|
53 |
fi |
|
54 |
else |
|
55 |
cd $(dirname $TARGET_PATH) |
|
56 |
ABSOLUTE_PATH="${PWD}/$(basename $TARGET_PATH)" |
|
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 |
|
57 | 44 |
fi |
58 |
cd $ORIGIN_PATH |
|
45 |
printf "$(tput setaf 1)>>> $string$(tput sgr 0)" 1>&2 |
|
46 |
} |
|
59 | 47 |
|
60 |
# return the result |
|
61 |
if [ $# -gt 1 ]; then |
|
62 |
eval $2="$ABSOLUTE_PATH" |
|
63 |
else |
|
64 |
echo $ABSOLUTE_PATH |
|
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 |
|
65 | 62 |
fi |
63 |
printf "$(tput setaf 3)>>> $string$(tput sgr 0)" |
|
64 |
} |
|
66 | 65 |
|
67 |
# cleanup |
|
68 |
unset TARGET_PATH |
|
69 |
unset ORIGIN_PATH |
|
70 |
unset ABSOLUTE_PATH |
|
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)" |
|
71 | 82 |
} |
72 |
#------------------------------------------------------------------------------- |
|
73 |
|
|
74 |
#------------------------------------------------------------------------------- |
|
75 |
# getRelativePath $1 $2 [$3] |
|
76 |
# |
|
77 |
# Computes the relative path from one to another location. |
|
78 |
# The result is then either stored in a specified variable, or just echoed. |
|
79 |
# arguments: |
|
80 |
# $1: the path to start from |
|
81 |
# If this is not a directory, only the path will be used |
|
82 |
# $2: the target location |
|
83 |
# $3: a variable to store the resulting path [optional] |
|
84 |
function getRelativePath { |
|
85 |
# make start and target location absolute |
|
86 |
START_PATH=$(toAbsolutePath $1) |
|
87 |
if [ ! -d $START_PATH ]; then |
|
88 |
START_PATH="$(dirname $START_PATH)/" |
|
89 |
fi |
|
90 |
TARGET_PATH=$(toAbsolutePath $2) |
|
91 |
|
|
92 |
# initialize the common prefix and the relative path from START_PATH to TARGET_PATH |
|
93 |
COMMON_PREFIX=$START_PATH |
|
94 |
RELATIVE_PATH="./" |
|
95 |
# while the common prefix is no substring of the target path |
|
96 |
while [ "${TARGET_PATH#$COMMON_PREFIX}" == "$TARGET_PATH" ]; do |
|
97 |
read |
|
98 |
# reduce the common prefix and record the relative path |
|
99 |
COMMON_PREFIX="$(dirname $COMMON_PREFIX)/" |
|
100 |
RELATIVE_PATH="../$RELATIVE_PATH" |
|
101 |
# special case: if only root is the common prefix, remove the just appended '/' |
|
102 |
if [ $COMMON_PREFIX == "//" ]; then |
|
103 |
COMMON_PREFIX="/" |
|
104 |
fi |
|
105 |
done |
|
106 | 83 |
|
107 |
# if the relative path is more than just the current directory, cut off the trailing './' |
|
108 |
if [ ! $RELATIVE_PATH == "./" ]; then |
|
109 |
RELATIVE_PATH=${RELATIVE_PATH::-2} |
|
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 |
|
110 | 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 |
} |
|
111 | 114 |
|
112 |
# compute the unique part of the target path |
|
113 |
UNIQUE_POSTFIX=${TARGET_PATH#$COMMON_PREFIX} |
|
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 |
} |
|
114 | 139 |
|
115 |
# append the unique postfix to the relative path |
|
116 |
RELATIVE_PATH=$RELATIVE_PATH$UNIQUE_POSTFIX |
|
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 |
} |
|
117 | 162 |
|
118 |
# return the result |
|
119 |
if [ $# -gt 2 ]; then |
|
120 |
eval $3="$RELATIVE_PATH" |
|
163 |
### set the log file ########################################################### |
|
164 |
# Sets a specified <infile> as log file and checks whether it already exists. |
|
165 |
# If so, the log may either be appended to the file, its content can be cleared, |
|
166 |
# or no log is generated at all. |
|
167 |
# The resulting path is stored in <outvar>. |
|
168 |
# |
|
169 |
# usage: setLogFile [--option=<option>] [--quiet] <infile> <outvar> |
|
170 |
# arguments: --option=<option> |
|
171 |
# Select what to do if <file> already exists. |
|
172 |
# Possible values are 'a', 'c', 'r' and 'n'. |
|
173 |
# - a: append (starts with a separator) |
|
174 |
# - c: continue (does not insert a seperator) |
|
175 |
# - r: delete and restart |
|
176 |
# - n: no log |
|
177 |
# If no option is secified but <file> exists, an interactive selection is provided. |
|
178 |
# --quiet |
|
179 |
# Suppress all messages. |
|
180 |
# <infile> |
|
181 |
# Path of the wanted log file. |
|
182 |
# <outvar> |
|
183 |
# Variable to store the path of the log file to. |
|
184 |
# return: 0 |
|
185 |
# No error or warning occurred. |
|
186 |
# -1 |
|
187 |
# Error: invalid input |
|
188 |
# |
|
189 |
function setLogFile { |
|
190 |
local filepath="" |
|
191 |
local option="" |
|
192 |
local quiet=false |
|
193 |
|
|
194 |
# parse arguments |
|
195 |
local otherargs=() |
|
196 |
while [ $# -gt 0 ]; do |
|
197 |
if ( parseIsOption $1 ); then |
|
198 |
case "$1" in |
|
199 |
-o=*|--option=*) |
|
200 |
option=${1#*=}; shift 1;; |
|
201 |
-o*|--option*) |
|
202 |
option="$2"; shift 2;; |
|
203 |
-q|--quiet) |
|
204 |
quiet=true; shift 1;; |
|
205 |
*) |
|
206 |
printError "invalid option: $1\n"; shift 1;; |
|
207 |
esac |
|
208 |
else |
|
209 |
otherargs+=("$1") |
|
210 |
shift 1 |
|
211 |
fi |
|
212 |
done |
|
213 |
filepath=$(realpath ${otherargs[0]}) |
|
214 |
|
|
215 |
# if file already exists |
|
216 |
if [ -e $filepath ]; then |
|
217 |
# if no option was specified, ask what to do |
|
218 |
if [ -z "$option" ]; then |
|
219 |
printWarning "log file $filepath already esists\n" |
|
220 |
local userinput="" |
|
221 |
printf "Select what to do:\n" |
|
222 |
printf " [A] - append log\n" |
|
223 |
printf " [R] - restart log (delete existing file)\n" |
|
224 |
printf " [N] - no log\n" |
|
225 |
readUserInput "AaRrNn" userinput |
|
226 |
option=${userinput,,} |
|
227 |
fi |
|
228 |
# evaluate option |
|
229 |
case "$option" in |
|
230 |
a|c) |
|
231 |
if [ $quiet = false ]; then |
|
232 |
printInfo "appending log to $filepath\n" |
|
233 |
fi |
|
234 |
if [ $option != c ]; then |
|
235 |
printf "\n" >> $filepath |
|
236 |
printf "######################################################################\n" >> $filepath |
|
237 |
printf "\n" >> $filepath |
|
238 |
fi |
|
239 |
;; |
|
240 |
r) |
|
241 |
echo -n "" > $filepath |
|
242 |
if [ $quiet = false ]; then |
|
243 |
printInfo "content of $filepath wiped\n" |
|
244 |
fi |
|
245 |
;; |
|
246 |
n) |
|
247 |
if [ $quiet = false ]; then |
|
248 |
printInfo "no log file will be generated\n" |
|
249 |
fi |
|
250 |
filepath="" |
|
251 |
;; |
|
252 |
*) # sanity check (return error) |
|
253 |
printError "unexpected argument: $option\n"; return -1;; |
|
254 |
esac |
|
121 | 255 |
else |
122 |
echo $RELATIVE_PATH |
|
256 |
if [ $quiet = false ]; then |
|
257 |
printInfo "log file set to $filepath\n" |
|
258 |
fi |
|
123 | 259 |
fi |
124 | 260 |
|
125 |
# clean up |
|
126 |
unset START_PATH |
|
127 |
unset TARGET_PATH |
|
128 |
unset COMMON_PREFIX |
|
129 |
unset RELATIVE_PATH |
|
130 |
unset UNIQUE_POSTFIX |
|
261 |
eval ${otherargs[1]}="$filepath" |
|
262 |
|
|
263 |
return 0 |
|
131 | 264 |
} |
132 |
#------------------------------------------------------------------------------- |
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
############################################################################### |
|
137 |
### INITIALIZATION ### |
|
138 |
############################################################################### |
|
139 |
|
|
140 |
# ignore case when comparing strings |
|
141 |
shopt -s nocasematch |
|
142 |
|
|
143 |
# detect what exactly should be done |
|
144 |
NOINFO_FLAG="NOINFO" |
|
145 |
HELP_FLAG="HELP" |
|
146 |
CLEAN_FLAG="CLEAN" |
|
147 |
WIPE_FLAG="WIPE" |
|
148 |
LIGHTRING_FLAG="LR" |
|
149 |
POWERMANAGEMENT_FLAG="PM" |
|
150 |
DIWHEELDRIVE_FLAG="DWD" |
|
151 |
|
|
152 |
# start with an empty array |
|
153 |
ARG_LIST=() |
|
154 |
# try to interpret all given arguments |
|
155 |
for ARG in "$@"; do |
|
156 |
case $ARG in |
|
157 |
"no_info") |
|
158 |
ARG_LIST+=( "$NOINFO_FLAG" ) |
|
159 |
;; |
|
160 |
"help") |
|
161 |
ARG_LIST+=( "$HELP_FLAG" ) |
|
162 |
;; |
|
163 |
"clean") |
|
164 |
ARG_LIST+=( "$CLEAN_FLAG" ) |
|
165 |
;; |
|
166 |
"wipe") |
|
167 |
ARG_LIST+=( "$WIPE_FLAG" ) |
|
168 |
;; |
|
169 |
"all") |
|
170 |
ARG_LIST+=( "$LIGHTRING_FLAG" "$POWERMANAGEMENT_FLAG" "$DIWHEELDRIVE_FLAG" ) |
|
171 |
;; |
|
172 |
"LightRing"|"LR") |
|
173 |
ARG_LIST+=( "$LIGHTRING_FLAG" ) |
|
174 |
;; |
|
175 |
"PowerManagement"|"PM") |
|
176 |
ARG_LIST+=( "$POWERMANAGEMENT_FLAG" ) |
|
177 |
;; |
|
178 |
"DiWheelDrive"|"DWD") |
|
179 |
ARG_LIST+=( "$DIWHEELDRIVE_FLAG" ) |
|
180 |
;; |
|
181 |
esac |
|
182 |
done |
|
183 |
|
|
184 |
# evaluate if a help text shall be printed and which further actions to take |
|
185 |
PRINT_INFO=true |
|
186 |
PRINT_HELP=false |
|
187 |
ACTION_REQUESTED=false |
|
188 |
for ARG in ${ARG_LIST[@]}; do |
|
189 |
case $ARG in |
|
190 |
$NOINFO_FLAG) |
|
191 |
PRINT_INFO=false |
|
192 |
;; |
|
193 |
$HELP_FLAG) |
|
194 |
PRINT_HELP=true |
|
195 |
;; |
|
196 |
$CLEAN_FLAG|$WIPE_FLAG|$LIGHTRING_FLAG|$POWERMANAGEMENT_FLAG|$DIWHEELDRIVE_FLAG) |
|
197 |
ACTION_REQUESTED=true |
|
198 |
;; |
|
199 |
*) |
|
200 |
PRINT_HELP=true |
|
201 |
;; |
|
202 |
esac |
|
203 |
done |
|
204 |
|
|
205 |
# print the info prompt |
|
206 |
if [[ $PRINT_INFO = true ]]; then |
|
207 |
|
|
208 |
############################################################################## |
|
209 |
### PRINT INFO ### |
|
210 |
############################################################################## |
|
211 | 265 |
|
266 |
################################################################################ |
|
267 |
# SPECIFIC FUNCTIONS # |
|
268 |
################################################################################ |
|
269 |
|
|
270 |
### print welcome text ######################################################### |
|
271 |
# Prints a welcome message to standard out. |
|
272 |
# |
|
273 |
# usage: printWelcomeText |
|
274 |
# arguments: n/a |
|
275 |
# return: n/a |
|
276 |
# |
|
277 |
function printWelcomeText { |
|
212 | 278 |
printf "######################################################################\n" |
213 | 279 |
printf "# #\n" |
214 |
printf "# Welcome to the AMiRo-BLT QtCreator IDE setup #\n"
|
|
280 |
printf "# Welcome to the QtCreator setup! #\n"
|
|
215 | 281 |
printf "# #\n" |
216 | 282 |
printf "######################################################################\n" |
217 | 283 |
printf "# #\n" |
218 |
printf "# Copyright (c) 2016..2017 Thomas Schöpping #\n"
|
|
284 |
printf "# Copyright (c) 2016..2018 Thomas Schöpping #\n"
|
|
219 | 285 |
printf "# #\n" |
220 | 286 |
printf "# This is free software; see the source for copying conditions. #\n" |
221 | 287 |
printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
... | ... | |
226 | 292 |
printf "# Excellence Initiative. #\n" |
227 | 293 |
printf "# #\n" |
228 | 294 |
printf "######################################################################\n" |
295 |
} |
|
296 |
|
|
297 |
### print help ################################################################# |
|
298 |
# Prints a help text to standard out. |
|
299 |
# |
|
300 |
# usage: printHelp |
|
301 |
# arguments: n/a |
|
302 |
# return: n/a |
|
303 |
# |
|
304 |
function printHelp { |
|
305 |
printInfo "printing help text\n" |
|
306 |
printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--clean] [-w|--wipe] [--LightRing] [--PowerManagement] [--DiWheelDrive] [-a|--all] [-q|--quit] [--log=<file>]\n" |
|
229 | 307 |
printf "\n" |
230 |
fi |
|
231 |
|
|
232 |
# print setup header |
|
233 |
printf "QtCreator projects setup\n" |
|
234 |
printf "========================\n" |
|
235 |
printf "\n" |
|
236 |
|
|
237 |
# print the help text |
|
238 |
if [[ ${#ARG_LIST[@]} == 0 || |
|
239 |
(${#ARG_LIST[@]} == 1 && ${ARG_LIST[0]} == "$NOINFO_FLAG") || |
|
240 |
$PRINT_HELP = true ]]; then |
|
241 |
|
|
242 |
############################################################################## |
|
243 |
### PRINT HELP ### |
|
244 |
############################################################################## |
|
245 |
|
|
246 |
printf "The following commands are available: \n" |
|
247 |
printf " \n" |
|
248 |
printf " help - Prints this help text. \n" |
|
249 |
printf " clean - Deletes all files created by this script. \n" |
|
250 |
printf " wipe - Deletes the .user files, created by QtCreator. \n" |
|
251 |
printf " LightRing - Creates a project for the LightRing module. \n" |
|
252 |
printf " PowerManagement - Creates a project for the PowerManagement module. \n" |
|
253 |
printf " DiWheelDrive - Creates a project for the DiWheelDrive module. \n" |
|
254 |
printf " all - Creates all three projects. \n" |
|
255 |
printf " \n" |
|
256 |
printf "Any of these commands can be combined, e.g. \n" |
|
257 |
printf " $> ./setup.sh PowerManagement DiWheelDrive \n" |
|
258 |
printf "will create two projects. \n" |
|
259 |
printf "\n" |
|
260 |
printf "Note that this script does not create a project for the SerialBoot \n" |
|
261 |
printf "application. Since it uses CMAKE, QtCreator can import it directly. \n" |
|
308 |
printf "options: -h, --help\n" |
|
309 |
printf " Print this help text.\n" |
|
310 |
printf " -c, --clean\n" |
|
311 |
printf " Delete project files.\n" |
|
312 |
printf " -w, --wipe\n" |
|
313 |
printf " Delete project and .user files.\n" |
|
314 |
printf " --LightRing\n" |
|
315 |
printf " Create project for the LightRing module.\n" |
|
316 |
printf " --PowerManagement\n" |
|
317 |
printf " Create project for the PowerManagement module.\n" |
|
318 |
printf " --DiWheelDrive\n" |
|
319 |
printf " Create project for the DiWheelDrive module.\n" |
|
320 |
printf " -a, --all\n" |
|
321 |
printf " Create projects for all modules.\n" |
|
322 |
printf " -q, --quit\n" |
|
323 |
printf " Quit the script.\n" |
|
324 |
printf " --log=<file>\n" |
|
325 |
printf " Specify a log file.\n" |
|
326 |
} |
|
262 | 327 |
|
263 |
fi |
|
328 |
### read directory where to create/delete projects ############################# |
|
329 |
# Read the directory where to create/delete project files from user. |
|
330 |
# |
|
331 |
# usage: getProjectDir <pathvar> |
|
332 |
# arguments: <pathvar> |
|
333 |
# Variable to store the selected path to. |
|
334 |
# return: n/a |
|
335 |
# |
|
336 |
function getProjectDir { |
|
337 |
printLog "reading path for project files from user...\n" |
|
338 |
local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../Target/) |
|
339 |
local input="" |
|
340 |
read -p "Path where to create/delete project files: " -i $amirobltdir -e input |
|
341 |
printLog "user selected path $(realpath $input)\n" |
|
342 |
eval $1="$(realpath $input)" |
|
343 |
} |
|
264 | 344 |
|
265 |
# execute action |
|
266 |
if [ $ACTION_REQUESTED = true ]; then |
|
345 |
### retrieves the ARM-NONE-EABI-GCC include directory ########################## |
|
346 |
# Retrieves the include directory of the currently set arm-none-eabi-gcc. |
|
347 |
# |
|
348 |
# usage: retrieveGccIncludeDir <path> |
|
349 |
# arguments: <path> |
|
350 |
# Variable to store the path to. |
|
351 |
# return: 0 |
|
352 |
# No error or warning occurred. |
|
353 |
# -1 |
|
354 |
# Error: Command 'arm-none-eabi-gcc' not found. |
|
355 |
# |
|
356 |
function retrieveGccIncludeDir { |
|
357 |
# retrieve binary path or link |
|
358 |
local binpath=$(which arm-none-eabi-gcc) |
|
359 |
if [ -z "$binpath" ]; then |
|
360 |
printError "command 'arm-none-eabi-gcc' not found\n" |
|
361 |
return -1 |
|
362 |
else |
|
363 |
|
|
364 |
# traverse any links |
|
365 |
while [ -L "$binpath" ]; do |
|
366 |
binpath=$(readlink $binpath) |
|
367 |
done |
|
368 |
printInfo "gcc-arm-none-eabi detected: $binpath\n" |
|
369 |
|
|
370 |
# return include path |
|
371 |
eval $1=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/) |
|
372 |
|
|
373 |
return 0 |
|
374 |
fi |
|
375 |
} |
|
267 | 376 |
|
268 |
############################################################################## |
|
269 |
### CONFIGURATION ### |
|
270 |
############################################################################## |
|
377 |
### delete project files ####################################################### |
|
378 |
# Deletes all project files and optionally .user files, too. |
|
379 |
# |
|
380 |
# usage: deleteProjects [-p|--path=<path>] [-o|--out=<var>] [-w|-wipe] |
|
381 |
# arguments: -p, --path <path> |
|
382 |
# Path where to delete the project files. |
|
383 |
# -o, --out <var> |
|
384 |
# Variable to store the path to. |
|
385 |
# -w, --wipe |
|
386 |
# Delete .user files as well. |
|
387 |
# return: |
|
388 |
# - 0: no error |
|
389 |
# - 1: warning: function aborted by user |
|
390 |
# - -1: error: unexpected user input |
|
391 |
function deleteProjects { |
|
392 |
local projectdir="" |
|
393 |
local outvar="" |
|
394 |
local wipe=false |
|
395 |
|
|
396 |
# parse arguments |
|
397 |
local otherargs=() |
|
398 |
while [ $# -gt 0 ]; do |
|
399 |
if ( parseIsOption $1 ); then |
|
400 |
case "$1" in |
|
401 |
-p=*|--path=*) |
|
402 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
|
403 |
-p|--path) |
|
404 |
projectdir=$(realpath "$2"); shift 2;; |
|
405 |
-o=*|--out=*) |
|
406 |
outvar=${1#*=}; shift 1;; |
|
407 |
-o|--out) |
|
408 |
outvar=$2; shift 2;; |
|
409 |
-w|--wipe) |
|
410 |
wipe=true; shift 1;; |
|
411 |
*) |
|
412 |
printError "invalid option: $1\n"; shift 1;; |
|
413 |
esac |
|
414 |
else |
|
415 |
otherargs+=("$1") |
|
416 |
shift 1 |
|
417 |
fi |
|
418 |
done |
|
271 | 419 |
|
272 |
# the current user dir |
|
273 |
USER_DIR="${PWD}/" |
|
420 |
# print message |
|
421 |
if [ $wipe != true ]; then |
|
422 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, and *.creator)\n" |
|
423 |
else |
|
424 |
printInfo "deleting all QtCreator project files (*.includes, *.files, *.config, *.creator, and *.user)\n" |
|
425 |
fi |
|
274 | 426 |
|
275 |
# the directory containing this script file |
|
276 |
toAbsolutePath $(dirname ${BASH_SOURCE[0]}) SCRIPT_DIR |
|
427 |
# read project directory if required |
|
428 |
if [ -z "$projectdir" ]; then |
|
429 |
getProjectDir projectdir |
|
430 |
fi |
|
277 | 431 |
|
278 |
# the root directory of the project |
|
279 |
toAbsolutePath ${SCRIPT_DIR}../.. PROJECT_ROOT_PATH |
|
432 |
# remove all project files |
|
433 |
rm ${projectdir}/LightRing.includes 2>&1 | tee -a $LOG_FILE |
|
434 |
rm ${projectdir}/PowerManagement.includes 2>&1 | tee -a $LOG_FILE |
|
435 |
rm ${projectdir}/DiWheelDrive.includes 2>&1 | tee -a $LOG_FILE |
|
280 | 436 |
|
281 |
# the relative path where all project files shall be generated
|
|
282 |
read -p "path where to create/delete the project files: " -i "$PROJECT_ROOT_PATH" -e QTCREATOR_FILES_PATH
|
|
283 |
toAbsolutePath $QTCREATOR_FILES_PATH QTCREATOR_FILES_PATH
|
|
437 |
rm ${projectdir}/LightRing.files 2>&1 | tee -a $LOG_FILE
|
|
438 |
rm ${projectdir}/PowerManagement.files 2>&1 | tee -a $LOG_FILE
|
|
439 |
rm ${projectdir}/DiWheelDrive.files 2>&1 | tee -a $LOG_FILE
|
|
284 | 440 |
|
285 |
# the include path for GCC specific headers |
|
286 |
ARM_NONE_EABI_GCC_BIN=$(which arm-none-eabi-gcc) |
|
287 |
while [ -L $ARM_NONE_EABI_GCC_BIN ]; do |
|
288 |
ARM_NONE_EABI_GCC_BIN=$(readlink $ARM_NONE_EABI_GCC_BIN) |
|
289 |
done |
|
290 |
toAbsolutePath "$(dirname $ARM_NONE_EABI_GCC_BIN)/../arm-none-eabi/include/" ARM_NONE_EABI_GCC_INCLUDE_PATH |
|
441 |
rm ${projectdir}/LightRing.config 2>&1 | tee -a $LOG_FILE |
|
442 |
rm ${projectdir}/PowerManagement.config 2>&1 | tee -a $LOG_FILE |
|
443 |
rm ${projectdir}/DiWheelDrive.config 2>&1 | tee -a $LOG_FILE |
|
291 | 444 |
|
292 |
# a common path for all projects |
|
293 |
COMMON_SOURCE_INCLUDE_PATH=${PROJECT_ROOT_PATH}Target/Source |
|
445 |
rm ${projectdir}/LightRing.creator 2>&1 | tee -a $LOG_FILE |
|
446 |
rm ${projectdir}/PowerManagement.creator 2>&1 | tee -a $LOG_FILE |
|
447 |
rm ${projectdir}/DiWheelDrive.creator 2>&1 | tee -a $LOG_FILE |
|
294 | 448 |
|
295 |
# the paths to the individual projects |
|
296 |
POWERMANAGEMENT_PROJECT_ROOT_PATH=${PROJECT_ROOT_PATH}Target/Demo/ARMCM4_STM32F405_Power_Management_GCC/Boot |
|
297 |
DIWHEELDRIVE_PROJECT_ROOT_PATH=${PROJECT_ROOT_PATH}Target/Demo/ARMCM3_STM32F103_DiWheelDrive_GCC/Boot |
|
298 |
LIGHTRING_PROJECT_ROOT_PATH=${PROJECT_ROOT_PATH}Target/Demo/ARMCM3_STM32F103_LightRing_GCC/Boot |
|
449 |
if [ $wipe == true ]; then |
|
450 |
rm ${projectdir}/LightRing.user 2>&1 | tee -a $LOG_FILE |
|
451 |
rm ${projectdir}/PowerManagement.user 2>&1 | tee -a $LOG_FILE |
|
452 |
rm ${projectdir}/DiWheelDrive.user 2>&1 | tee -a $LOG_FILE |
|
453 |
fi |
|
299 | 454 |
|
300 |
# the prefix names for the projects to be generated
|
|
301 |
LIGHTRING_PROJECT_PREFIX="LightRing"
|
|
302 |
POWERMANAGEMENT_PROJECT_PREFIX="PowerManagement"
|
|
303 |
DIWHEELDRIVE_PROJECT_PREFIX="DiWheelDrive"
|
|
455 |
# store the path to the output variable, if required
|
|
456 |
if [ ! -z "$outvar" ]; then
|
|
457 |
eval $outvar="$projectdir"
|
|
458 |
fi
|
|
304 | 459 |
|
305 |
printf "\n" |
|
460 |
return 0 |
|
461 |
} |
|
306 | 462 |
|
307 |
############################################################################## |
|
308 |
### SETUP ### |
|
309 |
############################################################################## |
|
463 |
### create LightRing project files ############################################# |
|
464 |
# Create project files for the LightRing module. |
|
465 |
# |
|
466 |
# usage: createLightRingProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
|
467 |
# arguments: -p, --path <path> |
|
468 |
# Path where to create the project files. |
|
469 |
# --gcc=<path> |
|
470 |
# Path to the GCC include directory. |
|
471 |
# -o, --out <var> |
|
472 |
# Variable to store the path to. |
|
473 |
# --gccout=<var> |
|
474 |
# Variable to store the path to the GCC include directory to. |
|
475 |
# return: 0 |
|
476 |
# No error or warning occurred. |
|
477 |
# |
|
478 |
function createLightRingProject { |
|
479 |
local userdir=$(pwd) |
|
480 |
local projectdir="" |
|
481 |
local gccincludedir="" |
|
482 |
local outvar="" |
|
483 |
local gccoutvar="" |
|
484 |
|
|
485 |
# parse arguments |
|
486 |
local otherargs=() |
|
487 |
while [ $# -gt 0 ]; do |
|
488 |
if ( parseIsOption $1 ); then |
|
489 |
case "$1" in |
|
490 |
-p=*|--path=*) |
|
491 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
|
492 |
-p|--path) |
|
493 |
projectdir=$(realpath "$2"); shift 2;; |
|
494 |
--gcc=*) |
|
495 |
gccincludedir=$(realpath "${1#*=}"); shift 1;; |
|
496 |
--gcc) |
|
497 |
gccincludedir=$(realpath "$2"); shift 2;; |
|
498 |
-o=*|--out=*) |
|
499 |
outvar=${1#*=}; shift 1;; |
|
500 |
-o|--out) |
|
501 |
outvar=$2; shift 2;; |
|
502 |
--gccout=*) |
|
503 |
gccoutvar=$(realpath "${1#*=}"); shift 1;; |
|
504 |
--gccout) |
|
505 |
gccoutvar=$(realpath "$2"); shift 2;; |
|
506 |
*) |
|
507 |
printError "invalid option: $1\n"; shift 1;; |
|
508 |
esac |
|
509 |
else |
|
510 |
otherargs+=("$1") |
|
511 |
shift 1 |
|
512 |
fi |
|
513 |
done |
|
310 | 514 |
|
311 |
# move to the project root directory
|
|
312 |
cd $QTCREATOR_FILES_PATH
|
|
515 |
# print message
|
|
516 |
printInfo "creating QtCreator project files for the LightRing module...\n"
|
|
313 | 517 |
|
314 |
for ARG in ${ARG_LIST[@]}; do |
|
315 |
case $ARG in |
|
518 |
# read absolute project directory if required |
|
519 |
if [ -z "$projectdir" ]; then |
|
520 |
getProjectDir projectdir |
|
521 |
fi |
|
316 | 522 |
|
317 |
########################################################################## |
|
318 |
### CLEAN STEP ### |
|
319 |
########################################################################## |
|
523 |
# retrieve absolute GCC include dir |
|
524 |
if [ -z "$gccincludedir" ]; then |
|
525 |
retrieveGccIncludeDir gccincludedir |
|
526 |
fi |
|
320 | 527 |
|
321 |
$CLEAN_FLAG) |
|
322 |
printf "removing project files..." |
|
528 |
# move to project directory |
|
529 |
cd $projectdir |
|
530 |
|
|
531 |
# create project files |
|
532 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
|
533 |
find $gccincludedir -type d > ${projectdir}/LightRing.includes |
|
534 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../Target/Source) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/LightRing.includes |
|
535 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_LightRing_GCC/Boot) -type d | grep -v "bin\|cmd\|ethernetlib\|fatfs\|uip\|obj" >> ${projectdir}/LightRing.includes |
|
536 |
# generate a file that specifies all files |
|
537 |
echo -n "" > ${projectdir}/LightRing.files |
|
538 |
for path in `cat ${projectdir}/LightRing.includes`; do |
|
539 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/LightRing.files |
|
540 |
done |
|
541 |
# generate a default project configuration file if none exists so far |
|
542 |
if [ ! -f ${projectdir}/LightRing.config ]; then |
|
543 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/LightRing.config |
|
544 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/LightRing.config |
|
545 |
echo -e "" >> ${projectdir}/LightRing.config |
|
546 |
fi |
|
547 |
# generate a default .creator file if none exists so far |
|
548 |
if [ ! -f ${projectdir}/LightRing.creator ]; then |
|
549 |
echo -e "[general]" > ${projectdir}/LightRing.creator |
|
550 |
echo -e "" >> ${projectdir}/LightRing.creator |
|
551 |
fi |
|
323 | 552 |
|
324 |
# remove all files |
|
325 |
rm ${LIGHTRING_PROJECT_PREFIX}.includes 2> /dev/null |
|
326 |
rm ${LIGHTRING_PROJECT_PREFIX}.files 2> /dev/null |
|
327 |
rm ${LIGHTRING_PROJECT_PREFIX}.config 2> /dev/null |
|
328 |
rm ${LIGHTRING_PROJECT_PREFIX}.creator 2> /dev/null |
|
553 |
# go back to user directory |
|
554 |
cd $userdir |
|
329 | 555 |
|
330 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.includes 2> /dev/null |
|
331 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.files 2> /dev/null |
|
332 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.config 2> /dev/null |
|
333 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.creator 2> /dev/null |
|
556 |
# fill the output variables |
|
557 |
if [ ! -z "$outvar" ]; then |
|
558 |
eval $outvar="$projectdir" |
|
559 |
fi |
|
560 |
if [ ! -z "$gccoutvar" ]; then |
|
561 |
eval $gccoutvar="$gccincludedir" |
|
562 |
fi |
|
334 | 563 |
|
335 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.includes 2> /dev/null |
|
336 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.files 2> /dev/null |
|
337 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.config 2> /dev/null |
|
338 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.creator 2> /dev/null |
|
564 |
return 0 |
|
565 |
} |
|
339 | 566 |
|
340 |
printf "\tdone\n" |
|
341 |
;; |
|
567 |
### create PowerManagement project files ####################################### |
|
568 |
# Create project files for the PowerManagement module. |
|
569 |
# |
|
570 |
# usage: createPowerManagementProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
|
571 |
# arguments: -p, --path <path> |
|
572 |
# Path where to create the project files. |
|
573 |
# --gcc=<path> |
|
574 |
# Path to the GCC include directory. |
|
575 |
# -o, --out <var> |
|
576 |
# Variable to store the path to. |
|
577 |
# --gccout=<var> |
|
578 |
# Variable to store the path to the GCC include directory to. |
|
579 |
# return: 0 |
|
580 |
# No error or warning occurred. |
|
581 |
# |
|
582 |
function createPowerManagementProject { |
|
583 |
local userdir=$(pwd) |
|
584 |
local projectdir="" |
|
585 |
local gccincludedir="" |
|
586 |
local outvar="" |
|
587 |
local gccoutvar="" |
|
588 |
|
|
589 |
# parse arguments |
|
590 |
local otherargs=() |
|
591 |
while [ $# -gt 0 ]; do |
|
592 |
if ( parseIsOption $1 ); then |
|
593 |
case "$1" in |
|
594 |
-p=*|--path=*) |
|
595 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
|
596 |
-p|--path) |
|
597 |
projectdir=$(realpath "$2"); shift 2;; |
|
598 |
--gcc=*) |
|
599 |
gccincludedir=$(realpath "${1#*=}"); shift 1;; |
|
600 |
--gcc) |
|
601 |
gccincludedir=$(realpath "$2"); shift 2;; |
|
602 |
-o=*|--out=*) |
|
603 |
outvar=${1#*=}; shift 1;; |
|
604 |
-o|--out) |
|
605 |
outvar=$2; shift 2;; |
|
606 |
--gccout=*) |
|
607 |
gccoutvar=$(realpath "${1#*=}"); shift 1;; |
|
608 |
--gccout) |
|
609 |
gccoutvar=$(realpath "$2"); shift 2;; |
|
610 |
*) |
|
611 |
printError "invalid option: $1\n"; shift 1;; |
|
612 |
esac |
|
613 |
else |
|
614 |
otherargs+=("$1") |
|
615 |
shift 1 |
|
616 |
fi |
|
617 |
done |
|
342 | 618 |
|
343 |
########################################################################## |
|
344 |
### WIPE STEP ### |
|
345 |
########################################################################## |
|
619 |
# print message |
|
620 |
printInfo "creating QtCreator project files for the PowerManagement module...\n" |
|
346 | 621 |
|
347 |
$WIPE_FLAG) |
|
348 |
printf "removing .user project files..." |
|
622 |
# read absolute project directory if required |
|
623 |
if [ -z "$projectdir" ]; then |
|
624 |
getProjectDir projectdir |
|
625 |
fi |
|
349 | 626 |
|
350 |
# remove all user files
|
|
351 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.creator.user 2> /dev/null
|
|
352 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.creator.user 2> /dev/null
|
|
353 |
rm ${LIGHTRING_PROJECT_PREFIX}.creator.user 2> /dev/null
|
|
627 |
# retrieve absolute GCC include dir
|
|
628 |
if [ -z "$gccincludedir" ]; then
|
|
629 |
retrieveGccIncludeDir gccincludedir
|
|
630 |
fi
|
|
354 | 631 |
|
355 |
printf "\tdone\n" |
|
356 |
;; |
|
632 |
# move to project directory |
|
633 |
cd $projectdir |
|
634 |
|
|
635 |
# create project files |
|
636 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
|
637 |
find $gccincludedir -type d > ${projectdir}/PowerManagement.includes |
|
638 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../Target/Source) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/PowerManagement.includes |
|
639 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM4_STM32F405_Power_Management_GCC/Boot) -type d | grep -v "bin\|cmd\|ethernetlib\|fatfs\|uip\|obj" >> ${projectdir}/PowerManagement.includes |
|
640 |
# generate a file that specifies all files |
|
641 |
echo -n "" > ${projectdir}/PowerManagement.files |
|
642 |
for path in `cat ${projectdir}/PowerManagement.includes`; do |
|
643 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/PowerManagement.files |
|
644 |
done |
|
645 |
# generate a default project configuration file if none exists so far |
|
646 |
if [ ! -f ${projectdir}/PowerManagement.config ]; then |
|
647 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/PowerManagement.config |
|
648 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/PowerManagement.config |
|
649 |
echo -e "" >> ${projectdir}/PowerManagement.config |
|
650 |
fi |
|
651 |
# generate a default .creator file if none exists so far |
|
652 |
if [ ! -f ${projectdir}/PowerManagement.creator ]; then |
|
653 |
echo -e "[general]" > ${projectdir}/PowerManagement.creator |
|
654 |
echo -e "" >> ${projectdir}/PowerManagement.creator |
|
655 |
fi |
|
357 | 656 |
|
358 |
########################################################################## |
|
359 |
### LIGHTRING SETUP ### |
|
360 |
########################################################################## |
|
657 |
# go back to user directory |
|
658 |
cd $userdir |
|
361 | 659 |
|
362 |
$LIGHTRING_FLAG) |
|
363 |
printf "creating project files for ${LIGHTRING_PROJECT_PREFIX} (STM32F103RET6)..." |
|
364 | 660 |
|
365 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
|
366 |
find $ARM_NONE_EABI_GCC_INCLUDE_PATH -type d > ${LIGHTRING_PROJECT_PREFIX}.includes |
|
367 |
find $COMMON_SOURCE_INCLUDE_PATH -type d | grep -v "ARMCM4_STM32" >> ${LIGHTRING_PROJECT_PREFIX}.includes |
|
368 |
find $LIGHTRING_PROJECT_ROOT_PATH -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${LIGHTRING_PROJECT_PREFIX}.includes |
|
661 |
# fill the output variables |
|
662 |
if [ ! -z "$outvar" ]; then |
|
663 |
eval $outvar="$projectdir" |
|
664 |
fi |
|
665 |
if [ ! -z "$gccoutvar" ]; then |
|
666 |
eval $gccoutvar="$gccincludedir" |
|
667 |
fi |
|
369 | 668 |
|
370 |
# generate a file that specifies all files |
|
371 |
echo -n "" > ${LIGHTRING_PROJECT_PREFIX}.files |
|
372 |
for path in `cat ${LIGHTRING_PROJECT_PREFIX}.includes`; do |
|
373 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${LIGHTRING_PROJECT_PREFIX}.files |
|
374 |
done |
|
669 |
return 0 |
|
670 |
} |
|
375 | 671 |
|
376 |
# generate a default project configuration file if none exists so far |
|
377 |
if [ ! -f ${LIGHTRING_PROJECT_PREFIX}.config ]; then |
|
378 |
echo -e "// Add predefined macros for your project here. For example:\n// #define YOUR_CONFIGURATION belongs here\n" > ${LIGHTRING_PROJECT_PREFIX}.config |
|
379 |
fi |
|
672 |
### create DiWheelDrive project files ########################################## |
|
673 |
# Create project files for the DiWheelDrive module. |
|
674 |
# |
|
675 |
# usage: createDiWheelDriveProject [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
|
676 |
# arguments: -p, --path <path> |
|
677 |
# Path where to create the project files. |
|
678 |
# --gcc=<path> |
|
679 |
# Path to the GCC include directory. |
|
680 |
# -o, --out <var> |
|
681 |
# Variable to store the path to. |
|
682 |
# --gccout=<var> |
|
683 |
# Variable to store the path to the GCC include directory to. |
|
684 |
# return: 0 |
|
685 |
# No error or warning occurred. |
|
686 |
# |
|
687 |
function createDiWheelDriveProject { |
|
688 |
local userdir=$(pwd) |
|
689 |
local projectdir="" |
|
690 |
local gccincludedir="" |
|
691 |
local outvar="" |
|
692 |
local gccoutvar="" |
|
693 |
|
|
694 |
# parse arguments |
|
695 |
local otherargs=() |
|
696 |
while [ $# -gt 0 ]; do |
|
697 |
if ( parseIsOption $1 ); then |
|
698 |
case "$1" in |
|
699 |
-p=*|--path=*) |
|
700 |
projectdir=$(realpath "${1#*=}"); shift 1;; |
|
701 |
-p|--path) |
|
702 |
projectdir=$(realpath "$2"); shift 2;; |
|
703 |
--gcc=*) |
|
704 |
gccincludedir=$(realpath "${1#*=}"); shift 1;; |
|
705 |
--gcc) |
|
706 |
gccincludedir=$(realpath "$2"); shift 2;; |
|
707 |
-o=*|--out=*) |
|
708 |
outvar=${1#*=}; shift 1;; |
|
709 |
-o|--out) |
|
710 |
outvar=$2; shift 2;; |
|
711 |
--gccout=*) |
|
712 |
gccoutvar=$(realpath "${1#*=}"); shift 1;; |
|
713 |
--gccout) |
|
714 |
gccoutvar=$(realpath "$2"); shift 2;; |
|
715 |
*) |
|
716 |
printError "invalid option: $1\n"; shift 1;; |
|
717 |
esac |
|
718 |
else |
|
719 |
otherargs+=("$1") |
|
720 |
shift 1 |
|
721 |
fi |
|
722 |
done |
|
380 | 723 |
|
381 |
# generate a default .creator file if none exists so far |
|
382 |
if [ ! -f ${LIGHTRING_PROJECT_PREFIX}.creator ]; then |
|
383 |
echo -e "[general]\n" > ${LIGHTRING_PROJECT_PREFIX}.creator |
|
384 |
fi |
|
724 |
# print message |
|
725 |
printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
|
385 | 726 |
|
386 |
printf "\tdone\n" |
|
387 |
;; |
|
727 |
# read absolute project directory if required |
|
728 |
if [ -z "$projectdir" ]; then |
|
729 |
getProjectDir projectdir |
|
730 |
fi |
|
388 | 731 |
|
389 |
########################################################################## |
|
390 |
### POWERMANAGEMENT SETUP ### |
|
391 |
########################################################################## |
|
732 |
# retrieve absolute GCC include dir |
|
733 |
if [ -z "$gccincludedir" ]; then |
|
734 |
retrieveGccIncludeDir gccincludedir |
|
735 |
fi |
|
392 | 736 |
|
393 |
$POWERMANAGEMENT_FLAG)
|
|
394 |
printf "creating project files for ${POWERMANAGEMENT_PROJECT_PREFIX} (STM32F405RGT6)..."
|
|
737 |
# move to project directory
|
|
738 |
cd $projectdir
|
|
395 | 739 |
|
396 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
|
397 |
find $ARM_NONE_EABI_GCC_INCLUDE_PATH -type d > ${POWERMANAGEMENT_PROJECT_PREFIX}.includes |
|
398 |
find $COMMON_SOURCE_INCLUDE_PATH -type d | grep -v "ARMCM3_STM32" >> ${POWERMANAGEMENT_PROJECT_PREFIX}.includes |
|
399 |
find $POWERMANAGEMENT_PROJECT_ROOT_PATH -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${POWERMANAGEMENT_PROJECT_PREFIX}.includes |
|
400 | 740 |
|
401 |
# generate a file that specifies all files |
|
402 |
echo -n "" > ${POWERMANAGEMENT_PROJECT_PREFIX}.files |
|
403 |
for path in `cat ${POWERMANAGEMENT_PROJECT_PREFIX}.includes`; do |
|
404 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${POWERMANAGEMENT_PROJECT_PREFIX}.files |
|
405 |
done |
|
741 |
# create project files |
|
742 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
|
743 |
find $gccincludedir -type d > ${projectdir}/DiWheelDrive.includes |
|
744 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../Target/Source) -type d | grep -v "ARMCM4_STM32" >> ${projectdir}/DiWheelDrive.includes |
|
745 |
find $(realpath --relative-base=$projectdir $(dirname ${BASH_SOURCE[0]})/../../Target/Demo/ARMCM3_STM32F103_DiWheelDrive_GCC/Boot) -type d | grep -v "bin\|cmd\|ethernetlib\|fatfs\|uip\|obj" >> ${projectdir}/DiWheelDrive.includes |
|
746 |
# generate a file that specifies all files |
|
747 |
echo -n "" > ${projectdir}/DiWheelDrive.files |
|
748 |
for path in `cat ${projectdir}/DiWheelDrive.includes`; do |
|
749 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${projectdir}/DiWheelDrive.files |
|
750 |
done |
|
751 |
# generate a default project configuration file if none exists so far |
|
752 |
if [ ! -f ${projectdir}/DiWheelDrive.config ]; then |
|
753 |
echo -e "// Add predefined macros for your project here. For example:" > ${projectdir}/DiWheelDrive.config |
|
754 |
echo -e "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/DiWheelDrive.config |
|
755 |
echo -e "" >> ${projectdir}/DiWheelDrive.config |
|
756 |
fi |
|
757 |
# generate a default .creator file if none exists so far |
|
758 |
if [ ! -f ${projectdir}/DiWheelDrive.creator ]; then |
|
759 |
echo -e "[general]" > ${projectdir}/DiWheelDrive.creator |
|
760 |
echo -e "" >> ${projectdir}/DiWheelDrive.creator |
|
761 |
fi |
|
406 | 762 |
|
407 |
# generate a default project configuration file if none exists so far |
|
408 |
if [ ! -f ${POWERMANAGEMENT_PROJECT_PREFIX}.config ]; then |
|
409 |
echo -e "// Add predefined macros for your project here. For example:\n// #define YOUR_CONFIGURATION belongs here\n" > ${POWERMANAGEMENT_PROJECT_PREFIX}.config |
|
410 |
fi |
|
763 |
# go back to user directory |
|
764 |
cd $userdir |
|
411 | 765 |
|
412 |
# generate a default .creator file if none exists so far |
|
413 |
if [ ! -f ${POWERMANAGEMENT_PROJECT_PREFIX}.creator ]; then |
|
414 |
echo -e "[general]\n" > ${POWERMANAGEMENT_PROJECT_PREFIX}.creator |
|
415 |
fi |
|
416 | 766 |
|
417 |
printf "\tdone\n" |
|
418 |
;; |
|
767 |
# fill the output variables |
|
768 |
if [ ! -z "$outvar" ]; then |
|
769 |
eval $outvar="$projectdir" |
|
770 |
fi |
|
771 |
if [ ! -z "$gccoutvar" ]; then |
|
772 |
eval $gccoutvar="$gccincludedir" |
|
773 |
fi |
|
419 | 774 |
|
420 |
########################################################################## |
|
421 |
### DIWHEELDRIVE SETUP ### |
|
422 |
########################################################################## |
|
775 |
return 0 |
|
776 |
} |
|
423 | 777 |
|
424 |
$DIWHEELDRIVE_FLAG) |
|
425 |
printf "creating project files for ${DIWHEELDRIVE_PROJECT_PREFIX} (STM32F103RET6)..." |
|
778 |
### create project files for al modules ######################################## |
|
779 |
# Create project files for all modules. |
|
780 |
# |
|
781 |
# usage: createAllProjects |
|
782 |
# arguments: n/a |
|
783 |
# return: 0 |
|
784 |
# No error or warning occurred. |
|
785 |
# |
|
786 |
function createAllProjects { |
|
787 |
# print message |
|
788 |
printInfo "creating QtCreator project files for the DiWheelDrive module...\n" |
|
426 | 789 |
|
427 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories)
|
|
428 |
find $ARM_NONE_EABI_GCC_INCLUDE_PATH -type d > ${DIWHEELDRIVE_PROJECT_PREFIX}.includes
|
|
429 |
find $COMMON_SOURCE_INCLUDE_PATH -type d | grep -v "ARMCM4_STM32" >> ${DIWHEELDRIVE_PROJECT_PREFIX}.includes
|
|
430 |
find $DIWHEELDRIVE_PROJECT_ROOT_PATH -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${DIWHEELDRIVE_PROJECT_PREFIX}.includes
|
|
790 |
# read project directory
|
|
791 |
local projectdir=""
|
|
792 |
getProjectDir projectdir
|
|
793 |
printInfo "files will be created in $projectdir\n"
|
|
431 | 794 |
|
432 |
# generate a file that specifies all files |
|
433 |
echo -n "" > ${DIWHEELDRIVE_PROJECT_PREFIX}.files |
|
434 |
for path in `cat ${DIWHEELDRIVE_PROJECT_PREFIX}.includes`; do |
|
435 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${DIWHEELDRIVE_PROJECT_PREFIX}.files |
|
436 |
done |
|
795 |
# retrieve gcc-arm-none-eabi include dir |
|
796 |
retrieveGccIncludeDir gccincludedir |
|
437 | 797 |
|
438 |
# generate a default project configuration file if none exists so far
|
|
439 |
if [ ! -f ${DIWHEELDRIVE_PROJECT_PREFIX}.config ]; then
|
|
440 |
echo -e "// Add predefined macros for your project here. For example:\n// #define YOUR_CONFIGURATION belongs here\n" > ${DIWHEELDRIVE_PROJECT_PREFIX}.config
|
|
441 |
fi
|
|
798 |
# create projects
|
|
799 |
createLightRingProject --path="$projectdir" --gcc="$gccincludedir"
|
|
800 |
createPowerManagementProject --path="$projectdir" --gcc="$gccincludedir"
|
|
801 |
createDiWheelDriveProject --path="$projectdir" --gcc="$gccincludedir"
|
|
442 | 802 |
|
443 |
# generate a default .creator file if none exists so far |
|
444 |
if [ ! -f ${DIWHEELDRIVE_PROJECT_PREFIX}.creator ]; then |
|
445 |
echo -e "[general]\n" > ${DIWHEELDRIVE_PROJECT_PREFIX}.creator |
|
446 |
fi |
|
803 |
return 0 |
|
804 |
} |
|
447 | 805 |
|
448 |
printf "\tdone\n" |
|
449 |
;; |
|
806 |
### main function of this script ############################################### |
|
807 |
# Creates, deletes and wipes QtCreator project files for the three AMiRo base modules. |
|
808 |
# |
|
809 |
# usage: see function printHelp |
|
810 |
# arguments: see function printHelp |
|
811 |
# return: 0 |
|
812 |
# No error or warning ocurred. |
|
813 |
# |
|
814 |
function main { |
|
815 |
# print welcome/info text if not suppressed |
|
816 |
if [[ $@ != *"--noinfo"* ]]; then |
|
817 |
printWelcomeText |
|
818 |
else |
|
819 |
printf "######################################################################\n" |
|
820 |
fi |
|
821 |
printf "\n" |
|
450 | 822 |
|
823 |
# if --help or -h was specified, print the help text and exit |
|
824 |
if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
|
825 |
printHelp |
|
826 |
printf "\n" |
|
827 |
quitScript |
|
828 |
fi |
|
829 |
|
|
830 |
# set log file if specified |
|
831 |
if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
|
832 |
# get the parameter (file name) |
|
833 |
local cmdidx=1 |
|
834 |
while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do |
|
835 |
cmdidx=$[cmdidx + 1] |
|
836 |
done |
|
837 |
local cmd="${!cmdidx}" |
|
838 |
local logfile="" |
|
839 |
if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
|
840 |
logfile=${cmd#*=} |
|
841 |
else |
|
842 |
local filenameidx=$((cmdidx + 1)) |
|
843 |
logfile="${!filenameidx}" |
|
844 |
fi |
|
845 |
# optionally force silent appending |
|
846 |
if [[ "$cmd" = "--LOG"* ]]; then |
|
847 |
setLogFile --option=c --quiet "$logfile" LOG_FILE |
|
848 |
else |
|
849 |
setLogFile "$logfile" LOG_FILE |
|
850 |
printf "\n" |
|
851 |
fi |
|
852 |
fi |
|
853 |
# log script name |
|
854 |
printLog "this is $(realpath ${BASH_SOURCE[0]})\n" |
|
855 |
|
|
856 |
# parse arguments |
|
857 |
local otherargs=() |
|
858 |
while [ $# -gt 0 ]; do |
|
859 |
if ( parseIsOption $1 ); then |
|
860 |
case "$1" in |
|
861 |
-h|--help) # already handled; ignore |
|
862 |
shift 1;; |
|
863 |
-c|--clean) |
|
864 |
deleteProjects; printf "\n"; shift 1;; |
|
865 |
-w|--wipe) |
|
866 |
deleteProjects --wipe; printf "\n"; shift 1;; |
|
867 |
--LightRing) |
|
868 |
createLightRingProject; printf "\n"; shift 1;; |
|
869 |
--PowerManagement) |
|
870 |
createPowerManagementProject; printf "\n"; shift 1;; |
|
871 |
--DiWheelDrive) |
|
872 |
createDiWheelDriveProject; printf "\n"; shift 1;; |
|
873 |
-a|--all) |
|
874 |
createAllProjects; printf "\n"; shift 1;; |
|
875 |
-q|--quit) |
|
876 |
quitScript; shift 1;; |
|
877 |
--log=*|--LOG=*) # already handled; ignore |
|
878 |
shift 1;; |
|
879 |
--log|--LOG) # already handled; ignore |
|
880 |
shift 2;; |
|
881 |
--noinfo) # already handled; ignore |
|
882 |
shift 1;; |
|
883 |
*) |
|
884 |
printError "invalid option: $1\n"; shift 1;; |
|
885 |
esac |
|
886 |
else |
|
887 |
otherargs+=("$1") |
|
888 |
shift 1 |
|
889 |
fi |
|
890 |
done |
|
891 |
|
|
892 |
# interactive menu |
|
893 |
while ( true ); do |
|
894 |
# main menu info prompt and selection |
|
895 |
printInfo "QtCreator setup main menu\n" |
|
896 |
printf "Please select one of the following actions:\n" |
|
897 |
printf " [C] - clean project files\n" |
|
898 |
printf " [W] - wipe project and .user files\n" |
|
899 |
printf " [L] - create a project for the LightRing module\n" |
|
900 |
printf " [P] - create a project for the PowerManagement module\n" |
|
901 |
printf " [D] - create a project for the DiWheelDrive module\n" |
|
902 |
printf " [A] - create a project for all modules\n" |
|
903 |
printf " [Q] - quit this setup\n" |
|
904 |
local userinput="" |
|
905 |
readUserInput "CcWwLlPpDdAaQq" userinput |
|
906 |
printf "\n" |
|
907 |
|
|
908 |
# evaluate user selection |
|
909 |
case "$userinput" in |
|
910 |
C|c) |
|
911 |
deleteProjects; printf "\n";; |
|
912 |
W|w) |
|
913 |
deleteProjects --wipe; printf "\n";; |
|
914 |
L|l) |
|
915 |
createLightRingProject; printf "\n";; |
|
916 |
P|p) |
|
917 |
createPowerManagementProject; printf "\n";; |
|
918 |
D|d) |
|
919 |
createDiWheelDriveProject; printf "\n";; |
|
920 |
A|a) |
|
921 |
createAllProjects; printf "\n";; |
|
922 |
Q|q) |
|
923 |
quitScript;; |
|
924 |
*) # sanity check (exit with error) |
|
925 |
printError "unexpected argument: $userinput\n";; |
|
451 | 926 |
esac |
452 | 927 |
done |
453 |
fi |
|
928 |
|
|
929 |
exit 0 |
|
930 |
} |
|
454 | 931 |
|
455 | 932 |
################################################################################ |
456 |
### OUTRO ###
|
|
933 |
# SCRIPT ENTRY POINT #
|
|
457 | 934 |
################################################################################ |
458 | 935 |
|
936 |
main "$@" |
|
937 |
|
Also available in: Unified diff