amiro-blt / tools / ide / QtCreator / QtCreatorSetup.sh @ 43464dd5
History | View | Annotate | Download (25.866 KB)
| 1 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
|---|---|---|---|
| 2 | 1da30dfc | Thomas Schöpping | # AMiRo-BLT is an bootloader and toolchain designed for the Autonomous Mini # |
| 3 | # Robot (AMiRo) platform. # |
||
| 4 | 94886d84 | Thomas Schöpping | # Copyright (C) 2016..2020 Thomas Schöpping et al. # |
| 5 | 4cce70a8 | Thomas Schöpping | # # |
| 6 | # This program is free software: you can redistribute it and/or modify # |
||
| 7 | # it under the terms of the GNU General Public License as published by # |
||
| 8 | # the Free Software Foundation, either version 3 of the License, or # |
||
| 9 | # (at your option) any later version. # |
||
| 10 | # # |
||
| 11 | # This program is distributed in the hope that it will be useful, # |
||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # |
||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
||
| 14 | # GNU General Public License for more details. # |
||
| 15 | # # |
||
| 16 | # You should have received a copy of the GNU General Public License # |
||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # |
||
| 18 | # # |
||
| 19 | # This research/work was supported by the Cluster of Excellence Cognitive # |
||
| 20 | # Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is # |
||
| 21 | # funded by the German Research Foundation (DFG). # |
||
| 22 | ################################################################################ |
||
| 23 | |||
| 24 | 69661903 | Thomas Schöpping | #!/bin/bash |
| 25 | |||
| 26 | ec50c96e | Thomas Schöpping | # load library |
| 27 | source "$(dirname ${BASH_SOURCE[0]})/../../bash/setuplib.sh"
|
||
| 28 | 1da30dfc | Thomas Schöpping | |
| 29 | 0a42f078 | Thomas Schöpping | ### print welcome text ######################################################### |
| 30 | # Prints a welcome message to standard out. |
||
| 31 | # |
||
| 32 | # usage: printWelcomeText |
||
| 33 | # arguments: n/a |
||
| 34 | # return: n/a |
||
| 35 | # |
||
| 36 | 1da30dfc | Thomas Schöpping | function printWelcomeText {
|
| 37 | 4cce70a8 | Thomas Schöpping | printf "######################################################################\n" |
| 38 | printf "# #\n" |
||
| 39 | 1da30dfc | Thomas Schöpping | printf "# Welcome to the QtCreator setup! #\n" |
| 40 | 4cce70a8 | Thomas Schöpping | printf "# #\n" |
| 41 | printf "######################################################################\n" |
||
| 42 | printf "# #\n" |
||
| 43 | 94886d84 | Thomas Schöpping | printf "# Copyright (c) 2016..2020 Thomas Schöpping #\n" |
| 44 | 4cce70a8 | Thomas Schöpping | printf "# #\n" |
| 45 | printf "# This is free software; see the source for copying conditions. #\n" |
||
| 46 | printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR #\n" |
||
| 47 | printf "# A PARTICULAR PURPOSE. The development of this software was #\n" |
||
| 48 | printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction #\n" |
||
| 49 | printf "# Technology. The Excellence Cluster EXC 227 is a grant of the #\n" |
||
| 50 | printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n" |
||
| 51 | printf "# Excellence Initiative. #\n" |
||
| 52 | printf "# #\n" |
||
| 53 | printf "######################################################################\n" |
||
| 54 | 1da30dfc | Thomas Schöpping | } |
| 55 | |||
| 56 | 0a42f078 | Thomas Schöpping | ### print help ################################################################# |
| 57 | # Prints a help text to standard out. |
||
| 58 | # |
||
| 59 | # usage: printHelp |
||
| 60 | # arguments: n/a |
||
| 61 | # return: n/a |
||
| 62 | # |
||
| 63 | 1da30dfc | Thomas Schöpping | function printHelp {
|
| 64 | printInfo "printing help text\n" |
||
| 65 | d5a2a7ce | Thomas Schöpping | printf "usage: $(basename ${BASH_SOURCE[0]}) [-h|--help] [-m|--module=<module>] [-a|--all] [-c|--clean] [-w|--wipe] [-q|--quit] [--log=<file>]\n"
|
| 66 | 0a42f078 | Thomas Schöpping | printf "\n" |
| 67 | printf "options: -h, --help\n" |
||
| 68 | printf " Print this help text.\n" |
||
| 69 | d5a2a7ce | Thomas Schöpping | printf " -m, --module <module>\n" |
| 70 | 6c75ad52 | Thomas Schöpping | printf " Create project for a single module.\n" |
| 71 | printf " -a, --all\n" |
||
| 72 | printf " Create projects for all modules.\n" |
||
| 73 | 0a42f078 | Thomas Schöpping | printf " -c, --clean\n" |
| 74 | printf " Delete project files.\n" |
||
| 75 | printf " -w, --wipe\n" |
||
| 76 | printf " Delete project and .user files.\n" |
||
| 77 | printf " -q, --quit\n" |
||
| 78 | printf " Quit the script.\n" |
||
| 79 | printf " --log=<file>\n" |
||
| 80 | printf " Specify a log file.\n" |
||
| 81 | 1da30dfc | Thomas Schöpping | } |
| 82 | 69661903 | Thomas Schöpping | |
| 83 | 0a42f078 | Thomas Schöpping | ### read directory where to create/delete projects ############################# |
| 84 | # Read the directory where to create/delete project files from user. |
||
| 85 | # |
||
| 86 | # usage: getProjectDir <pathvar> |
||
| 87 | # arguments: <pathvar> |
||
| 88 | # Variable to store the selected path to. |
||
| 89 | # return: n/a |
||
| 90 | # |
||
| 91 | 1da30dfc | Thomas Schöpping | function getProjectDir {
|
| 92 | 0a42f078 | Thomas Schöpping | printLog "reading path for project files from user...\n" |
| 93 | 9085c3a0 | Thomas Schöpping | local amirobltdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/)
|
| 94 | 0a42f078 | Thomas Schöpping | local input="" |
| 95 | read -p "Path where to create/delete project files: " -i $amirobltdir -e input |
||
| 96 | printLog "user selected path $(realpath $input)\n" |
||
| 97 | eval $1="$(realpath $input)" |
||
| 98 | 1da30dfc | Thomas Schöpping | } |
| 99 | 69661903 | Thomas Schöpping | |
| 100 | 0a42f078 | Thomas Schöpping | ### retrieves the ARM-NONE-EABI-GCC include directory ########################## |
| 101 | # Retrieves the include directory of the currently set arm-none-eabi-gcc. |
||
| 102 | # |
||
| 103 | # usage: retrieveGccIncludeDir <path> |
||
| 104 | # arguments: <path> |
||
| 105 | # Variable to store the path to. |
||
| 106 | # return: 0 |
||
| 107 | # No error or warning occurred. |
||
| 108 | # -1 |
||
| 109 | # Error: Command 'arm-none-eabi-gcc' not found. |
||
| 110 | 6c75ad52 | Thomas Schöpping | # -2 |
| 111 | d5a2a7ce | Thomas Schöpping | # Error: include directory could not be resolved. |
| 112 | 0a42f078 | Thomas Schöpping | # |
| 113 | 1da30dfc | Thomas Schöpping | function retrieveGccIncludeDir {
|
| 114 | # retrieve binary path or link |
||
| 115 | 0a42f078 | Thomas Schöpping | local binpath=$(which arm-none-eabi-gcc) |
| 116 | 6c75ad52 | Thomas Schöpping | local gccincpath="" |
| 117 | 1da30dfc | Thomas Schöpping | if [ -z "$binpath" ]; then |
| 118 | 0a42f078 | Thomas Schöpping | printError "command 'arm-none-eabi-gcc' not found\n" |
| 119 | 1da30dfc | Thomas Schöpping | return -1 |
| 120 | 0a42f078 | Thomas Schöpping | else |
| 121 | 69661903 | Thomas Schöpping | |
| 122 | 0a42f078 | Thomas Schöpping | # traverse any links |
| 123 | while [ -L "$binpath" ]; do |
||
| 124 | 7737db33 | Thomas Schöpping | binpath=$(realpath $(dirname $binpath)/$(readlink $binpath)) |
| 125 | 0a42f078 | Thomas Schöpping | done |
| 126 | printInfo "gcc-arm-none-eabi detected: $binpath\n" |
||
| 127 | 69661903 | Thomas Schöpping | |
| 128 | 0a42f078 | Thomas Schöpping | # return include path |
| 129 | 6c75ad52 | Thomas Schöpping | gccincpath=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
|
| 130 | if [ ! -d "$gccincpath" ]; then |
||
| 131 | printWarning "$gccincpath does not exist\n" |
||
| 132 | return -2 |
||
| 133 | else |
||
| 134 | eval $1="$gccincpath" |
||
| 135 | return 0 |
||
| 136 | fi |
||
| 137 | 0a42f078 | Thomas Schöpping | fi |
| 138 | 1da30dfc | Thomas Schöpping | } |
| 139 | 69661903 | Thomas Schöpping | |
| 140 | 6c75ad52 | Thomas Schöpping | ### detect available modules ################################################### |
| 141 | # Detect all avalable modules supported by AMiRo-OS. |
||
| 142 | 0a42f078 | Thomas Schöpping | # |
| 143 | 6c75ad52 | Thomas Schöpping | # usage: detectModules <modulearray> |
| 144 | # arguments: <modulearray> |
||
| 145 | # Array variable to store all detected modules to. |
||
| 146 | # return: n/a |
||
| 147 | # |
||
| 148 | function detectModules {
|
||
| 149 | local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/Modules)
|
||
| 150 | local modules_detected=() |
||
| 151 | 69661903 | Thomas Schöpping | |
| 152 | 6c75ad52 | Thomas Schöpping | # detect all available modules (via directories) |
| 153 | for dir in $(ls -d ${modulesdir}/*/); do
|
||
| 154 | modules_detected[${#modules_detected[@]}]=$(basename $dir)
|
||
| 155 | 4cce70a8 | Thomas Schöpping | done |
| 156 | 69661903 | Thomas Schöpping | |
| 157 | 6c75ad52 | Thomas Schöpping | # set the output variable |
| 158 | eval "$1=(${modules_detected[*]})"
|
||
| 159 | 1da30dfc | Thomas Schöpping | } |
| 160 | 4cce70a8 | Thomas Schöpping | |
| 161 | 6c75ad52 | Thomas Schöpping | ### create project files for a single module ################################### |
| 162 | # Create project files for a single module. |
||
| 163 | 0a42f078 | Thomas Schöpping | # |
| 164 | 6c75ad52 | Thomas Schöpping | # usage: createModuleProject <modules> [-m|--module=<module>] [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
| 165 | # arguments: <modules> |
||
| 166 | # Array containing all modules available. |
||
| 167 | # -m, --module <module> |
||
| 168 | # Name (folder name) of the module for which project files shall be generated. |
||
| 169 | # -p, --path <path> |
||
| 170 | 0a42f078 | Thomas Schöpping | # Path where to create the project files. |
| 171 | # --gcc=<path> |
||
| 172 | # Path to the GCC include directory. |
||
| 173 | # -o, --out <var> |
||
| 174 | # Variable to store the path to. |
||
| 175 | # --gccout=<var> |
||
| 176 | # Variable to store the path to the GCC include directory to. |
||
| 177 | 6c75ad52 | Thomas Schöpping | # If this optional arguments is absent, ths function will ask for user input. |
| 178 | 0a42f078 | Thomas Schöpping | # return: 0 |
| 179 | # No error or warning occurred. |
||
| 180 | 6c75ad52 | Thomas Schöpping | # 1 |
| 181 | # Aborted by user. |
||
| 182 | # -1 |
||
| 183 | # No modules available. |
||
| 184 | # -2 |
||
| 185 | # The specified <module> could not be found. |
||
| 186 | # -3 |
||
| 187 | # Parsing the project for the specified module failed. |
||
| 188 | # -4 |
||
| 189 | # Missing dependencies. |
||
| 190 | 0a42f078 | Thomas Schöpping | # |
| 191 | 6c75ad52 | Thomas Schöpping | function createModuleProject {
|
| 192 | cc06d380 | Thomas Schöpping | local userdir=$(pwd) |
| 193 | 6c75ad52 | Thomas Schöpping | local modulesdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../Target/Modules)
|
| 194 | local modules=("${!1}")
|
||
| 195 | local module="" |
||
| 196 | local moduleidx="" |
||
| 197 | 1da30dfc | Thomas Schöpping | local projectdir="" |
| 198 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
| 199 | 1da30dfc | Thomas Schöpping | local outvar="" |
| 200 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
| 201 | 4cce70a8 | Thomas Schöpping | |
| 202 | 6c75ad52 | Thomas Schöpping | # check dependencies |
| 203 | checkCommands make |
||
| 204 | if [ $? -ne 0 ]; then |
||
| 205 | printError "Missing dependencies detected.\n" |
||
| 206 | return -4 |
||
| 207 | fi |
||
| 208 | |||
| 209 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 210 | local otherargs=() |
||
| 211 | while [ $# -gt 0 ]; do |
||
| 212 | if ( parseIsOption $1 ); then |
||
| 213 | case "$1" in |
||
| 214 | 6c75ad52 | Thomas Schöpping | -m=*|--module=*) |
| 215 | module="${1#*=}"; shift 1;;
|
||
| 216 | -m|--module) |
||
| 217 | module="$2"; shift 2;; |
||
| 218 | 0a42f078 | Thomas Schöpping | -p=*|--path=*) |
| 219 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 220 | -p|--path) |
||
| 221 | projectdir=$(realpath "$2"); shift 2;; |
||
| 222 | --gcc=*) |
||
| 223 | gccincludedir=$(realpath "${1#*=}"); shift 1;;
|
||
| 224 | --gcc) |
||
| 225 | gccincludedir=$(realpath "$2"); shift 2;; |
||
| 226 | -o=*|--out=*) |
||
| 227 | outvar=${1#*=}; shift 1;;
|
||
| 228 | -o|--out) |
||
| 229 | outvar=$2; shift 2;; |
||
| 230 | --gccout=*) |
||
| 231 | gccoutvar=$(realpath "${1#*=}"); shift 1;;
|
||
| 232 | --gccout) |
||
| 233 | gccoutvar=$(realpath "$2"); shift 2;; |
||
| 234 | *) |
||
| 235 | printError "invalid option: $1\n"; shift 1;; |
||
| 236 | esac |
||
| 237 | else |
||
| 238 | otherargs+=("$1")
|
||
| 239 | shift 1 |
||
| 240 | fi |
||
| 241 | 1da30dfc | Thomas Schöpping | done |
| 242 | |||
| 243 | 6c75ad52 | Thomas Schöpping | # sanity check for the modules variable |
| 244 | if [ -z "${modules[*]}" ]; then
|
||
| 245 | printError "no modules available\n" |
||
| 246 | return -1 |
||
| 247 | fi |
||
| 248 | |||
| 249 | # select module |
||
| 250 | if [ -z $module ]; then |
||
| 251 | # list all available modules |
||
| 252 | printInfo "choose a module or type 'A' to abort:\n" |
||
| 253 | for (( idx=0; idx<${#modules[@]}; ++idx )); do
|
||
| 254 | printf "%4u: %s\n" $(($idx + 1)) "${modules[$idx]}"
|
||
| 255 | done |
||
| 256 | # read user input |
||
| 257 | printLog "read user selection\n" |
||
| 258 | local userinput="" |
||
| 259 | while [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#modules[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; do
|
||
| 260 | read -p "your selection: " -e userinput |
||
| 261 | printLog "user selection: $userinput\n" |
||
| 262 | if [[ ! "$userinput" =~ ^[0-9]+$ ]] || [ ! "$userinput" -gt 0 ] || [ ! "$userinput" -le ${#modules[@]} ] && [[ ! "$userinput" =~ ^[Aa]$ ]]; then
|
||
| 263 | printWarning "Please enter an integer between 1 and ${#modules[@]} or 'A' to abort.\n"
|
||
| 264 | fi |
||
| 265 | done |
||
| 266 | if [[ "$userinput" =~ ^[Aa]$ ]]; then |
||
| 267 | printWarning "aborted by user\n" |
||
| 268 | return 1 |
||
| 269 | fi |
||
| 270 | # store selection |
||
| 271 | moduleidx=$(($userinput - 1)) |
||
| 272 | module="${modules[$moduleidx]}"
|
||
| 273 | printf "\n" |
||
| 274 | else |
||
| 275 | # search all modules for the selected one |
||
| 276 | for (( idx=0; idx<${#modules[@]}; ++idx )); do
|
||
| 277 | if [ "${modules[$idx]}" = "$module" ]; then
|
||
| 278 | moduleidx=$idx |
||
| 279 | break |
||
| 280 | fi |
||
| 281 | done |
||
| 282 | # error if the module could not be found |
||
| 283 | if [ -z $moduleidx ]; then |
||
| 284 | printError "module ($module) not available\n" |
||
| 285 | return -2 |
||
| 286 | fi |
||
| 287 | fi |
||
| 288 | 1da30dfc | Thomas Schöpping | |
| 289 | cc06d380 | Thomas Schöpping | # read absolute project directory if required |
| 290 | 1da30dfc | Thomas Schöpping | if [ -z "$projectdir" ]; then |
| 291 | getProjectDir projectdir |
||
| 292 | 6c75ad52 | Thomas Schöpping | printf "\n" |
| 293 | fi |
||
| 294 | |||
| 295 | # check for existing project files |
||
| 296 | local projectfiles="$(find ${projectdir} -maxdepth 1 -type f | grep -E "${module}\.(includes|files|config|creator)$")"
|
||
| 297 | IFS=$'\n'; projectfiles=($projectfiles); unset IFS |
||
| 298 | if [ ! -z "${projectfiles[*]}" ]; then
|
||
| 299 | printWarning "The following files will be overwritten:\n" |
||
| 300 | for pfile in ${projectfiles[@]}; do
|
||
| 301 | printWarning "\t$(basename $pfile)\n" |
||
| 302 | done |
||
| 303 | local userinput="" |
||
| 304 | printInfo "Continue and overwrite? [y/n]\n" |
||
| 305 | readUserInput "YyNn" userinput |
||
| 306 | case "$userinput" in |
||
| 307 | Y|y) |
||
| 308 | ;; |
||
| 309 | N|n) |
||
| 310 | printWarning "Project generation for ${module} module aborted by user\n"
|
||
| 311 | return 1 |
||
| 312 | ;; |
||
| 313 | *) |
||
| 314 | printError "unexpected input: ${userinput}\n"; return -999;;
|
||
| 315 | esac |
||
| 316 | printf "\n" |
||
| 317 | 1da30dfc | Thomas Schöpping | fi |
| 318 | |||
| 319 | 6c75ad52 | Thomas Schöpping | # print message |
| 320 | printInfo "generating QtCreator project files for the $module module...\n" |
||
| 321 | |||
| 322 | # retrieve absolute GCC include path |
||
| 323 | 1da30dfc | Thomas Schöpping | if [ -z "$gccincludedir" ]; then |
| 324 | 0a42f078 | Thomas Schöpping | retrieveGccIncludeDir gccincludedir |
| 325 | 1da30dfc | Thomas Schöpping | fi |
| 326 | |||
| 327 | 6c75ad52 | Thomas Schöpping | # change to project directory |
| 328 | local amirobltrootdir=$(realpath $(dirname ${BASH_SOURCE[0]})/../../..)
|
||
| 329 | cd "$projectdir" |
||
| 330 | |||
| 331 | # run make, but only run the GCC preprocessor and produce no binaries |
||
| 332 | local sourcefiles=() |
||
| 333 | local sourcefile="" |
||
| 334 | local parse_state="WAIT_FOR_INCLUDE_OR_COMPILE" |
||
| 335 | # capture all output from make and GCC and append the return value of make as last line |
||
| 336 | printInfo "processing project (this may take a while)...\n" |
||
| 337 | local rawout=$(make --directory ${amirobltrootdir}/Target/Modules/${module}/Boot --always-make USER_CFLAGS="-v -H" 2>&1 && echo $?)
|
||
| 338 | # check whether the make call was successfull |
||
| 339 | if [[ $(echo "${rawout}" | tail -n 1) != "0" ]]; then
|
||
| 340 | printError "executing 'make' in module directory failed\n" |
||
| 341 | cd "$userdir" |
||
| 342 | return -3 |
||
| 343 | fi |
||
| 344 | # extract file names from raw output |
||
| 345 | IFS=$'\n'; rawout=($rawout); unset IFS |
||
| 346 | for line in "${rawout[@]}"; do
|
||
| 347 | case $parse_state in |
||
| 348 | WAIT_FOR_INCLUDE_OR_COMPILE) |
||
| 349 | # lines stating included files look like: |
||
| 350 | # ... <../relative/path/to/file> |
||
| 351 | if [[ "$line" =~ ^\.+[[:blank:]].+\..+$ ]]; then |
||
| 352 | sourcefile=${line##* }
|
||
| 353 | if [[ ! "$sourcefile" =~ ^/ ]]; then |
||
| 354 | sourcefile=$(realpath ${amirobltrootdir}/Target/Modules/${module}/Boot/${sourcefile})
|
||
| 355 | fi |
||
| 356 | sourcefiles[${#sourcefiles[@]}]="$sourcefile"
|
||
| 357 | # whenever the next source file is processed, a message appears like: |
||
| 358 | d5a2a7ce | Thomas Schöpping | # Compiling <filename> |
| 359 | 6c75ad52 | Thomas Schöpping | elif [[ "$line" =~ ^\+\+\+[[:blank:]]Compiling[[:blank:]]\[(.+\.c)\]$ ]]; then |
| 360 | printf "." |
||
| 361 | sourcefile=${BASH_REMATCH[1]}
|
||
| 362 | parse_state="WAIT_FOR_COMPILERCALL" |
||
| 363 | fi;; |
||
| 364 | WAIT_FOR_COMPILERCALL) |
||
| 365 | # wait for the actual call of the compiler to retrieve the full path to the source file |
||
| 366 | if [[ "$line" == *${sourcefile}* ]]; then
|
||
| 367 | line="${line%%${sourcefile}*}${sourcefile}"
|
||
| 368 | sourcefile=$(realpath ${amirobltrootdir}/Target/Modules/${module}/Boot/${line##* })
|
||
| 369 | sourcefiles[${#sourcefiles[@]}]="$sourcefile"
|
||
| 370 | parse_state="WAIT_FOR_INCLUDE_OR_COMPILE" |
||
| 371 | fi;; |
||
| 372 | esac |
||
| 373 | done |
||
| 374 | unset rawout |
||
| 375 | printf "\n" |
||
| 376 | # sort and remove duplicates |
||
| 377 | IFS=$'\n'; sourcefiles=($(sort --unique <<< "${sourcefiles[*]}")); unset IFS
|
||
| 378 | |||
| 379 | # extract include paths |
||
| 380 | local includes=() |
||
| 381 | for source in ${sourcefiles[*]}; do
|
||
| 382 | includes[${#includes[@]}]="$(dirname ${source})"
|
||
| 383 | done |
||
| 384 | # sort and remove duplicates |
||
| 385 | IFS=$'\n'; includes=($(sort --unique <<< "${includes[*]}")); unset IFS
|
||
| 386 | |||
| 387 | d5a2a7ce | Thomas Schöpping | # generate the .incldues file, containing all include paths |
| 388 | 6c75ad52 | Thomas Schöpping | echo "" > ${projectdir}/${module}.includes
|
| 389 | for inc in ${includes[*]}; do
|
||
| 390 | echo "$inc" >> ${projectdir}/${module}.includes
|
||
| 391 | 1da30dfc | Thomas Schöpping | done |
| 392 | d5a2a7ce | Thomas Schöpping | # generate the .files file, containing all source files |
| 393 | 6c75ad52 | Thomas Schöpping | echo "" > ${projectdir}/${module}.files
|
| 394 | for source in ${sourcefiles[*]}; do
|
||
| 395 | # skip GCC files |
||
| 396 | if [[ ! "$source" =~ .*/gcc.* ]]; then |
||
| 397 | echo "$source" >> ${projectdir}/${module}.files
|
||
| 398 | fi |
||
| 399 | done |
||
| 400 | # generate a default project configuration file if it doesn't exist yet |
||
| 401 | if [ ! -f ${projectdir}/${module}.config ]; then
|
||
| 402 | echo "// Add predefined macros for your project here. For example:" > ${projectdir}/${module}.config
|
||
| 403 | echo "// #define YOUR_CONFIGURATION belongs here" >> ${projectdir}/${module}.config
|
||
| 404 | 1da30dfc | Thomas Schöpping | fi |
| 405 | 6c75ad52 | Thomas Schöpping | # generate a default .creator file if it doesn't exist yet |
| 406 | if [ ! -f ${projectdir}/${module}.creator ]; then
|
||
| 407 | echo "[general]" > ${projectdir}/${module}.creator
|
||
| 408 | 1da30dfc | Thomas Schöpping | fi |
| 409 | |||
| 410 | cc06d380 | Thomas Schöpping | # go back to user directory |
| 411 | cd $userdir |
||
| 412 | |||
| 413 | 0a42f078 | Thomas Schöpping | # fill the output variables |
| 414 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
| 415 | eval $outvar="$projectdir" |
||
| 416 | fi |
||
| 417 | 0a42f078 | Thomas Schöpping | if [ ! -z "$gccoutvar" ]; then |
| 418 | eval $gccoutvar="$gccincludedir" |
||
| 419 | fi |
||
| 420 | 4cce70a8 | Thomas Schöpping | |
| 421 | 1da30dfc | Thomas Schöpping | return 0 |
| 422 | } |
||
| 423 | 4cce70a8 | Thomas Schöpping | |
| 424 | 6c75ad52 | Thomas Schöpping | ### create project files for all modules ####################################### |
| 425 | # Create project files for all modules. |
||
| 426 | 0a42f078 | Thomas Schöpping | # |
| 427 | 6c75ad52 | Thomas Schöpping | # usage: createAllProjects <modules> [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>] |
| 428 | # arguments: <modules> |
||
| 429 | # Array containing all modules available. |
||
| 430 | # -p, --path <path> |
||
| 431 | 0a42f078 | Thomas Schöpping | # Path where to create the project files. |
| 432 | # --gcc=<path> |
||
| 433 | # Path to the GCC include directory. |
||
| 434 | # -o, --out <var> |
||
| 435 | # Variable to store the path to. |
||
| 436 | # --gccout=<var> |
||
| 437 | # Variable to store the path to the GCC include directory to. |
||
| 438 | 6c75ad52 | Thomas Schöpping | # If this optional arguments is absent, ths function will ask for user input. |
| 439 | 0a42f078 | Thomas Schöpping | # return: 0 |
| 440 | # No error or warning occurred. |
||
| 441 | 6c75ad52 | Thomas Schöpping | # 1 |
| 442 | # Aborted by user. |
||
| 443 | # -1 |
||
| 444 | # No modules available. |
||
| 445 | 0a42f078 | Thomas Schöpping | # |
| 446 | 6c75ad52 | Thomas Schöpping | function createAllProjects {
|
| 447 | local modules=("${!1}")
|
||
| 448 | d5a2a7ce | Thomas Schöpping | local projectsdir="" |
| 449 | 0a42f078 | Thomas Schöpping | local gccincludedir="" |
| 450 | 1da30dfc | Thomas Schöpping | local outvar="" |
| 451 | 0a42f078 | Thomas Schöpping | local gccoutvar="" |
| 452 | 4cce70a8 | Thomas Schöpping | |
| 453 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 454 | local otherargs=() |
||
| 455 | while [ $# -gt 0 ]; do |
||
| 456 | if ( parseIsOption $1 ); then |
||
| 457 | case "$1" in |
||
| 458 | -p=*|--path=*) |
||
| 459 | d5a2a7ce | Thomas Schöpping | projectsdir=$(realpath "${1#*=}"); shift 1;;
|
| 460 | 0a42f078 | Thomas Schöpping | -p|--path) |
| 461 | d5a2a7ce | Thomas Schöpping | projectsdir=$(realpath "$2"); shift 2;; |
| 462 | 0a42f078 | Thomas Schöpping | --gcc=*) |
| 463 | gccincludedir=$(realpath "${1#*=}"); shift 1;;
|
||
| 464 | --gcc) |
||
| 465 | gccincludedir=$(realpath "$2"); shift 2;; |
||
| 466 | -o=*|--out=*) |
||
| 467 | outvar=${1#*=}; shift 1;;
|
||
| 468 | -o|--out) |
||
| 469 | outvar=$2; shift 2;; |
||
| 470 | --gccout=*) |
||
| 471 | gccoutvar=$(realpath "${1#*=}"); shift 1;;
|
||
| 472 | --gccout) |
||
| 473 | gccoutvar=$(realpath "$2"); shift 2;; |
||
| 474 | *) |
||
| 475 | printError "invalid option: $1\n"; shift 1;; |
||
| 476 | esac |
||
| 477 | else |
||
| 478 | otherargs+=("$1")
|
||
| 479 | shift 1 |
||
| 480 | fi |
||
| 481 | 1da30dfc | Thomas Schöpping | done |
| 482 | |||
| 483 | 6c75ad52 | Thomas Schöpping | # sanity check for the modules variable |
| 484 | if [ -z "${modules[*]}" ]; then
|
||
| 485 | printError "no modules available\n" |
||
| 486 | return -1 |
||
| 487 | fi |
||
| 488 | 4cce70a8 | Thomas Schöpping | |
| 489 | cc06d380 | Thomas Schöpping | # read absolute project directory if required |
| 490 | d5a2a7ce | Thomas Schöpping | if [ -z "$projectsdir" ]; then |
| 491 | getProjectDir projectsdir |
||
| 492 | 1da30dfc | Thomas Schöpping | fi |
| 493 | |||
| 494 | 6c75ad52 | Thomas Schöpping | # check for existing project files |
| 495 | 768babc5 | Thomas Schöpping | local projectfiles=() |
| 496 | 6c75ad52 | Thomas Schöpping | for module in ${modules[@]}; do
|
| 497 | 768babc5 | Thomas Schöpping | projectfiles+=($(find ${projectsdir} -maxdepth 1 -type f -regextype posix-extended -regex "^.*/${module}\.(includes|files|config|creator)$" | sort))
|
| 498 | 1da30dfc | Thomas Schöpping | done |
| 499 | 6c75ad52 | Thomas Schöpping | if [ ! -z "${projectfiles[*]}" ]; then
|
| 500 | printWarning "The following files will be removed:\n" |
||
| 501 | for pfile in ${projectfiles[@]}; do
|
||
| 502 | printWarning "\t$(basename $pfile)\n" |
||
| 503 | done |
||
| 504 | local userinput="" |
||
| 505 | printInfo "Continue and overwrite? [y/n]\n" |
||
| 506 | readUserInput "YyNn" userinput |
||
| 507 | case "${userinput}" in
|
||
| 508 | Y|y) |
||
| 509 | 768babc5 | Thomas Schöpping | for pfile in ${projectfiles[@]}; do
|
| 510 | 6c75ad52 | Thomas Schöpping | rm "$pfile" |
| 511 | done |
||
| 512 | ;; |
||
| 513 | N|n) |
||
| 514 | printWarning "Project generation aborted by user\n" |
||
| 515 | return 1 |
||
| 516 | ;; |
||
| 517 | *) |
||
| 518 | printError "unexpected input: ${userinput}\n"
|
||
| 519 | return 999 |
||
| 520 | ;; |
||
| 521 | esac |
||
| 522 | 1da30dfc | Thomas Schöpping | fi |
| 523 | 4cce70a8 | Thomas Schöpping | |
| 524 | 6c75ad52 | Thomas Schöpping | # print message |
| 525 | printf "\n" |
||
| 526 | printInfo "generating QtCreator project files for all modules...\n" |
||
| 527 | cc06d380 | Thomas Schöpping | |
| 528 | 6c75ad52 | Thomas Schöpping | # retrieve absolute GCC include path |
| 529 | if [ -z "$gccincludedir" ]; then |
||
| 530 | retrieveGccIncludeDir gccincludedir |
||
| 531 | 0a42f078 | Thomas Schöpping | fi |
| 532 | 4cce70a8 | Thomas Schöpping | |
| 533 | 6c75ad52 | Thomas Schöpping | # iterate over all modules |
| 534 | local retval=1 |
||
| 535 | for module in ${modules[@]}; do
|
||
| 536 | if [ $retval != 0 ]; then |
||
| 537 | printf "\n" |
||
| 538 | fi |
||
| 539 | d5a2a7ce | Thomas Schöpping | createModuleProject modules[@] --module="$module" --path="$projectsdir" --gcc="$gccincludedir" |
| 540 | 6c75ad52 | Thomas Schöpping | retval=$? |
| 541 | done |
||
| 542 | |||
| 543 | 1da30dfc | Thomas Schöpping | return 0 |
| 544 | } |
||
| 545 | 4cce70a8 | Thomas Schöpping | |
| 546 | 6c75ad52 | Thomas Schöpping | ### delete project files ####################################################### |
| 547 | # Deletes all project files and optionally .user files, too. |
||
| 548 | 0a42f078 | Thomas Schöpping | # |
| 549 | 6c75ad52 | Thomas Schöpping | # usage: deleteProjects [-p|--path=<path>] [-m|--module=<module>] [-o|--out=<var>] [-w|-wipe] |
| 550 | 0a42f078 | Thomas Schöpping | # arguments: -p, --path <path> |
| 551 | 6c75ad52 | Thomas Schöpping | # Path where to delete the project files. |
| 552 | # -m, --module <module> |
||
| 553 | # Module name for which the project files shall be deleted. |
||
| 554 | 0a42f078 | Thomas Schöpping | # -o, --out <var> |
| 555 | # Variable to store the path to. |
||
| 556 | 6c75ad52 | Thomas Schöpping | # -w, --wipe |
| 557 | # Delete .user files as well. |
||
| 558 | # return: |
||
| 559 | # - 0: no error |
||
| 560 | 0a42f078 | Thomas Schöpping | # |
| 561 | 6c75ad52 | Thomas Schöpping | function deleteProjects {
|
| 562 | local modulename="" |
||
| 563 | 1da30dfc | Thomas Schöpping | local projectdir="" |
| 564 | local outvar="" |
||
| 565 | 6c75ad52 | Thomas Schöpping | local wipe=false |
| 566 | local files="" |
||
| 567 | 4cce70a8 | Thomas Schöpping | |
| 568 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 569 | local otherargs=() |
||
| 570 | while [ $# -gt 0 ]; do |
||
| 571 | if ( parseIsOption $1 ); then |
||
| 572 | case "$1" in |
||
| 573 | -p=*|--path=*) |
||
| 574 | projectdir=$(realpath "${1#*=}"); shift 1;;
|
||
| 575 | -p|--path) |
||
| 576 | projectdir=$(realpath "$2"); shift 2;; |
||
| 577 | 6c75ad52 | Thomas Schöpping | -m=*|--module=*) |
| 578 | modulename="${1#*=}"; shift 1;;
|
||
| 579 | -m|--module) |
||
| 580 | modulename="${2}"; shift 2;;
|
||
| 581 | 0a42f078 | Thomas Schöpping | -o=*|--out=*) |
| 582 | outvar=${1#*=}; shift 1;;
|
||
| 583 | -o|--out) |
||
| 584 | outvar=$2; shift 2;; |
||
| 585 | 6c75ad52 | Thomas Schöpping | -w|--wipe) |
| 586 | wipe=true; shift 1;; |
||
| 587 | 0a42f078 | Thomas Schöpping | *) |
| 588 | printError "invalid option: $1\n"; shift 1;; |
||
| 589 | esac |
||
| 590 | else |
||
| 591 | otherargs+=("$1")
|
||
| 592 | shift 1 |
||
| 593 | fi |
||
| 594 | 1da30dfc | Thomas Schöpping | done |
| 595 | 4cce70a8 | Thomas Schöpping | |
| 596 | cc06d380 | Thomas Schöpping | # read absolute project directory if required |
| 597 | 1da30dfc | Thomas Schöpping | if [ -z "$projectdir" ]; then |
| 598 | getProjectDir projectdir |
||
| 599 | fi |
||
| 600 | 4cce70a8 | Thomas Schöpping | |
| 601 | 6c75ad52 | Thomas Schöpping | # list all files to be deleted |
| 602 | if [ -z "$modulename" ]; then |
||
| 603 | if [ $wipe != true ]; then |
||
| 604 | 768babc5 | Thomas Schöpping | files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator|cflags|cxxflags)$" | sort)
|
| 605 | 6c75ad52 | Thomas Schöpping | else |
| 606 | 768babc5 | Thomas Schöpping | files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^.+\.(includes|files|config|creator|cflags|cxxflags|creator(\.user(\..+)?)?)$" | sort)
|
| 607 | 6c75ad52 | Thomas Schöpping | fi |
| 608 | else |
||
| 609 | if [ $wipe != true ]; then |
||
| 610 | 768babc5 | Thomas Schöpping | files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^${modulename}\.(includes|files|config|creator|cflags|cxxflags)$" | sort)
|
| 611 | 6c75ad52 | Thomas Schöpping | else |
| 612 | 768babc5 | Thomas Schöpping | files=$(find "${projectdir}" -maxdepth 1 -type f | grep -E "^${modulename}\.(includes|files|config|creator|cflags|cxxflags|creator(\.user(\..+)?)?)$" | sort)
|
| 613 | 6c75ad52 | Thomas Schöpping | fi |
| 614 | 1da30dfc | Thomas Schöpping | fi |
| 615 | 6c75ad52 | Thomas Schöpping | if [ ! -z "$files" ]; then |
| 616 | printInfo "Deleting the following files:\n" |
||
| 617 | while read line; do |
||
| 618 | printInfo "\t$(basename ${line})\n"
|
||
| 619 | rm ${line} 2>&1 | tee -a $LOG_FILE
|
||
| 620 | done <<< "${files}"
|
||
| 621 | else |
||
| 622 | printInfo "No project files found\n" |
||
| 623 | 1da30dfc | Thomas Schöpping | fi |
| 624 | 4cce70a8 | Thomas Schöpping | |
| 625 | 6c75ad52 | Thomas Schöpping | # store the path to the output variable, if required |
| 626 | 1da30dfc | Thomas Schöpping | if [ ! -z "$outvar" ]; then |
| 627 | eval $outvar="$projectdir" |
||
| 628 | fi |
||
| 629 | 4cce70a8 | Thomas Schöpping | |
| 630 | 1da30dfc | Thomas Schöpping | return 0 |
| 631 | } |
||
| 632 | 4cce70a8 | Thomas Schöpping | |
| 633 | 0a42f078 | Thomas Schöpping | ### main function of this script ############################################### |
| 634 | d5a2a7ce | Thomas Schöpping | # Creates, deletes and wipes QtCreator project files for any module supported by AMiRo-OS. |
| 635 | 0a42f078 | Thomas Schöpping | # |
| 636 | # usage: see function printHelp |
||
| 637 | # arguments: see function printHelp |
||
| 638 | # return: 0 |
||
| 639 | # No error or warning ocurred. |
||
| 640 | # |
||
| 641 | 1da30dfc | Thomas Schöpping | function main {
|
| 642 | 0a42f078 | Thomas Schöpping | # print welcome/info text if not suppressed |
| 643 | 1da30dfc | Thomas Schöpping | if [[ $@ != *"--noinfo"* ]]; then |
| 644 | printWelcomeText |
||
| 645 | else |
||
| 646 | printf "######################################################################\n" |
||
| 647 | fi |
||
| 648 | printf "\n" |
||
| 649 | |||
| 650 | 1446566f | Thomas Schöpping | # if --help or -h was specified, print the help text and exit |
| 651 | if [[ $@ == *"--help"* || $@ == *"-h"* ]]; then |
||
| 652 | printHelp |
||
| 653 | printf "\n" |
||
| 654 | quitScript |
||
| 655 | fi |
||
| 656 | |||
| 657 | 1da30dfc | Thomas Schöpping | # set log file if specified |
| 658 | 0a42f078 | Thomas Schöpping | if [[ $@ == *"--log"* ]] || [[ $@ == *"--LOG"* ]]; then |
| 659 | 1da30dfc | Thomas Schöpping | # get the parameter (file name) |
| 660 | local cmdidx=1 |
||
| 661 | 0a42f078 | Thomas Schöpping | while [[ ! "${!cmdidx}" = "--log"* ]] && [[ ! "${!cmdidx}" = "--LOG"* ]]; do
|
| 662 | 1da30dfc | Thomas Schöpping | cmdidx=$[cmdidx + 1] |
| 663 | done |
||
| 664 | 0a42f078 | Thomas Schöpping | local cmd="${!cmdidx}"
|
| 665 | local logfile="" |
||
| 666 | if [[ "$cmd" = "--log="* ]] || [[ "$cmd" = "--LOG="* ]]; then |
||
| 667 | logfile=${cmd#*=}
|
||
| 668 | else |
||
| 669 | local filenameidx=$((cmdidx + 1)) |
||
| 670 | logfile="${!filenameidx}"
|
||
| 671 | fi |
||
| 672 | 1da30dfc | Thomas Schöpping | # optionally force silent appending |
| 673 | 0a42f078 | Thomas Schöpping | if [[ "$cmd" = "--LOG"* ]]; then |
| 674 | 0dc9f2f9 | Thomas Schöpping | setLogFile --option=c --quiet "$logfile" LOG_FILE |
| 675 | 1da30dfc | Thomas Schöpping | else |
| 676 | 0a42f078 | Thomas Schöpping | setLogFile "$logfile" LOG_FILE |
| 677 | 1da30dfc | Thomas Schöpping | printf "\n" |
| 678 | fi |
||
| 679 | fi |
||
| 680 | # log script name |
||
| 681 | printLog "this is $(realpath ${BASH_SOURCE[0]})\n"
|
||
| 682 | 4cce70a8 | Thomas Schöpping | |
| 683 | 6c75ad52 | Thomas Schöpping | # detect available modules and inform user |
| 684 | local modules=() |
||
| 685 | detectModules modules |
||
| 686 | case "${#modules[@]}" in
|
||
| 687 | 0) |
||
| 688 | printInfo "no module has been detected\n";; |
||
| 689 | 1) |
||
| 690 | printInfo "1 module has been detected:\n";; |
||
| 691 | *) |
||
| 692 | printInfo "${#modules[@]} modules have been detected:\n"
|
||
| 693 | esac |
||
| 694 | for (( idx=0; idx<${#modules[@]}; ++idx )); do
|
||
| 695 | printInfo " - ${modules[$idx]}\n"
|
||
| 696 | done |
||
| 697 | printf "\n" |
||
| 698 | |||
| 699 | 0a42f078 | Thomas Schöpping | # parse arguments |
| 700 | local otherargs=() |
||
| 701 | while [ $# -gt 0 ]; do |
||
| 702 | if ( parseIsOption $1 ); then |
||
| 703 | case "$1" in |
||
| 704 | -h|--help) # already handled; ignore |
||
| 705 | shift 1;; |
||
| 706 | 6c75ad52 | Thomas Schöpping | -m=*|--module=*) |
| 707 | createModuleProject modules[@] --module="${1#*=}"; printf "\n"; shift 1;;
|
||
| 708 | -m|--module) |
||
| 709 | createModuleProject modules[@] --module="${2}"; printf "\n"; shift 2;;
|
||
| 710 | -a|--all) |
||
| 711 | createAllProjects modules[@]; shift 1;; |
||
| 712 | 0a42f078 | Thomas Schöpping | -c|--clean) |
| 713 | deleteProjects; printf "\n"; shift 1;; |
||
| 714 | -w|--wipe) |
||
| 715 | deleteProjects --wipe; printf "\n"; shift 1;; |
||
| 716 | -q|--quit) |
||
| 717 | quitScript; shift 1;; |
||
| 718 | --log=*|--LOG=*) # already handled; ignore |
||
| 719 | shift 1;; |
||
| 720 | --log|--LOG) # already handled; ignore |
||
| 721 | shift 2;; |
||
| 722 | --noinfo) # already handled; ignore |
||
| 723 | shift 1;; |
||
| 724 | *) |
||
| 725 | printError "invalid option: $1\n"; shift 1;; |
||
| 726 | esac |
||
| 727 | else |
||
| 728 | otherargs+=("$1")
|
||
| 729 | shift 1 |
||
| 730 | fi |
||
| 731 | 1da30dfc | Thomas Schöpping | done |
| 732 | 4cce70a8 | Thomas Schöpping | |
| 733 | 6c75ad52 | Thomas Schöpping | # interactive menu |
| 734 | 0a42f078 | Thomas Schöpping | while ( true ); do |
| 735 | 1da30dfc | Thomas Schöpping | # main menu info prompt and selection |
| 736 | printInfo "QtCreator setup main menu\n" |
||
| 737 | printf "Please select one of the following actions:\n" |
||
| 738 | 6c75ad52 | Thomas Schöpping | printf " [M] - create a project for a single module\n" |
| 739 | 1da30dfc | Thomas Schöpping | printf " [A] - create a project for all modules\n" |
| 740 | 6c75ad52 | Thomas Schöpping | printf " [C] - clean all project files\n" |
| 741 | printf " [W] - wipe all project and .user files\n" |
||
| 742 | 1da30dfc | Thomas Schöpping | printf " [Q] - quit this setup\n" |
| 743 | 0a42f078 | Thomas Schöpping | local userinput="" |
| 744 | 6c75ad52 | Thomas Schöpping | readUserInput "MmAaCcWwQq" userinput |
| 745 | 1da30dfc | Thomas Schöpping | printf "\n" |
| 746 | |||
| 747 | # evaluate user selection |
||
| 748 | 0a42f078 | Thomas Schöpping | case "$userinput" in |
| 749 | 6c75ad52 | Thomas Schöpping | M|m) |
| 750 | createModuleProject modules[@]; printf "\n";; |
||
| 751 | A|a) |
||
| 752 | createAllProjects modules[@]; printf "\n";; |
||
| 753 | 1da30dfc | Thomas Schöpping | C|c) |
| 754 | 0a42f078 | Thomas Schöpping | deleteProjects; printf "\n";; |
| 755 | 1da30dfc | Thomas Schöpping | W|w) |
| 756 | 0a42f078 | Thomas Schöpping | deleteProjects --wipe; printf "\n";; |
| 757 | 1da30dfc | Thomas Schöpping | Q|q) |
| 758 | 0a42f078 | Thomas Schöpping | quitScript;; |
| 759 | 1da30dfc | Thomas Schöpping | *) # sanity check (exit with error) |
| 760 | 0a42f078 | Thomas Schöpping | printError "unexpected argument: $userinput\n";; |
| 761 | 4cce70a8 | Thomas Schöpping | esac |
| 762 | done |
||
| 763 | 1da30dfc | Thomas Schöpping | |
| 764 | exit 0 |
||
| 765 | } |
||
| 766 | 69661903 | Thomas Schöpping | |
| 767 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 768 | 1da30dfc | Thomas Schöpping | # SCRIPT ENTRY POINT # |
| 769 | 4cce70a8 | Thomas Schöpping | ################################################################################ |
| 770 | 69661903 | Thomas Schöpping | |
| 771 | 1da30dfc | Thomas Schöpping | main "$@" |