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