Statistics
| Branch: | Tag: | Revision:

amiro-blt / ide / QtCreator / QtCreatorSetup.sh @ a3508d90

History | View | Annotate | Download (19.175 KB)

1 4cce70a8 Thomas Schöpping
################################################################################
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.                            #
5
#                                                                              #
6
# This program is free software: you can redistribute it and/or modify         #
7
# it under the terms of the GNU General Public License as published by         #
8
# the Free Software Foundation, either version 3 of the License, or            #
9
# (at your option) any later version.                                          #
10
#                                                                              #
11
# This program is distributed in the hope that it will be useful,              #
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
14
# GNU General Public License for more details.                                 #
15
#                                                                              #
16
# You should have received a copy of the GNU General Public License            #
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.        #
18
#                                                                              #
19
# This research/work was supported by the Cluster of Excellence Cognitive      #
20
# Interaction Technology 'CITEC' (EXC 277) at Bielefeld University, which is   #
21
# funded by the German Research Foundation (DFG).                              #
22
################################################################################
23
24 69661903 Thomas Schöpping
#!/bin/bash
25
26 4cce70a8 Thomas Schöpping
################################################################################
27
###   HELPER FUNCTIONS                                                       ###
28
################################################################################
29 69661903 Thomas Schöpping
30 4cce70a8 Thomas Schöpping
#-------------------------------------------------------------------------------
31 69661903 Thomas Schöpping
# 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)"
57
  fi
58
  cd $ORIGIN_PATH
59
60
  # return the result
61
  if [ $# -gt 1 ]; then
62
    eval $2="$ABSOLUTE_PATH"
63
  else
64
    echo $ABSOLUTE_PATH
65
  fi
66
67
  # cleanup
68
  unset TARGET_PATH
69
  unset ORIGIN_PATH
70
  unset ABSOLUTE_PATH
71
}
72 4cce70a8 Thomas Schöpping
#-------------------------------------------------------------------------------
73 69661903 Thomas Schöpping
74 4cce70a8 Thomas Schöpping
#-------------------------------------------------------------------------------
75 69661903 Thomas Schöpping
# 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
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}
110
  fi
111
112
  # compute the unique part of the target path
113
  UNIQUE_POSTFIX=${TARGET_PATH#$COMMON_PREFIX}
114
115
  # append the unique postfix to the relative path
116
  RELATIVE_PATH=$RELATIVE_PATH$UNIQUE_POSTFIX
117
118
  # return the result
119
  if [ $# -gt 2 ]; then
120
    eval $3="$RELATIVE_PATH"
121
  else
122
    echo $RELATIVE_PATH
123
  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
}
132 4cce70a8 Thomas Schöpping
#-------------------------------------------------------------------------------
133 69661903 Thomas Schöpping
134
135
136
###############################################################################
137
###   INITIALIZATION                                                        ###
138
###############################################################################
139
140 4cce70a8 Thomas Schöpping
# ignore case when comparing strings
141
shopt -s nocasematch
142 69661903 Thomas Schöpping
143 4cce70a8 Thomas Schöpping
# 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 69661903 Thomas Schöpping
done
183
184 4cce70a8 Thomas Schöpping
# 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 69661903 Thomas Schöpping
      ;;
193 4cce70a8 Thomas Schöpping
    $HELP_FLAG)
194
      PRINT_HELP=true
195 69661903 Thomas Schöpping
      ;;
196 4cce70a8 Thomas Schöpping
    $CLEAN_FLAG|$WIPE_FLAG|$LIGHTRING_FLAG|$POWERMANAGEMENT_FLAG|$DIWHEELDRIVE_FLAG)
197
      ACTION_REQUESTED=true
198 69661903 Thomas Schöpping
      ;;
199
    *)
200 4cce70a8 Thomas Schöpping
      PRINT_HELP=true
201 69661903 Thomas Schöpping
      ;;
202 4cce70a8 Thomas Schöpping
  esac
203
done
204 69661903 Thomas Schöpping
205 4cce70a8 Thomas Schöpping
# print the info prompt
206
if [[ $PRINT_INFO = true ]]; then
207
208
  ##############################################################################
209
  ###   PRINT INFO                                                           ###
210
  ##############################################################################
211
212
  printf "######################################################################\n"
213
  printf "#                                                                    #\n"
214
  printf "#            Welcome to the AMiRo-BLT QtCreator IDE setup            #\n"
215
  printf "#                                                                    #\n"
216
  printf "######################################################################\n"
217
  printf "#                                                                    #\n"
218
  printf "# Copyright (c) 2016..2017  Thomas Schöpping                         #\n"
219
  printf "#                                                                    #\n"
220
  printf "# This is free software; see the source for copying conditions.      #\n"
221
  printf "# There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR  #\n"
222
  printf "# A PARTICULAR PURPOSE. The development of this software was         #\n"
223
  printf "# supported by the Excellence Cluster EXC 227 Cognitive Interaction  #\n"
224
  printf "# Technology. The Excellence Cluster EXC 227 is a grant of the       #\n"
225
  printf "# Deutsche Forschungsgemeinschaft (DFG) in the context of the German #\n"
226
  printf "# Excellence Initiative.                                             #\n"
227
  printf "#                                                                    #\n"
228
  printf "######################################################################\n"
229
  printf "\n"
230
fi
231 69661903 Thomas Schöpping
232 4cce70a8 Thomas Schöpping
# 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"
262 69661903 Thomas Schöpping
263 4cce70a8 Thomas Schöpping
fi
264 69661903 Thomas Schöpping
265 4cce70a8 Thomas Schöpping
# execute action
266
if [ $ACTION_REQUESTED = true ]; then
267 69661903 Thomas Schöpping
268 4cce70a8 Thomas Schöpping
  ##############################################################################
269
  ###   CONFIGURATION                                                        ###
270
  ##############################################################################
271 69661903 Thomas Schöpping
272 4cce70a8 Thomas Schöpping
  # the current user dir
273
  USER_DIR="${PWD}/"
274 69661903 Thomas Schöpping
275 4cce70a8 Thomas Schöpping
  # the directory containing this script file
276
  toAbsolutePath $(dirname ${BASH_SOURCE[0]}) SCRIPT_DIR
277 69661903 Thomas Schöpping
278 4cce70a8 Thomas Schöpping
  # the root directory of the project
279
  toAbsolutePath ${SCRIPT_DIR}../.. PROJECT_ROOT_PATH
280 69661903 Thomas Schöpping
281 4cce70a8 Thomas Schöpping
  # 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
284 69661903 Thomas Schöpping
285 4cce70a8 Thomas Schöpping
  # 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
291 69661903 Thomas Schöpping
292 4cce70a8 Thomas Schöpping
  # a common path for all projects
293
  COMMON_SOURCE_INCLUDE_PATH=${PROJECT_ROOT_PATH}Target/Source
294 69661903 Thomas Schöpping
295 4cce70a8 Thomas Schöpping
  # 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
299 69661903 Thomas Schöpping
300 4cce70a8 Thomas Schöpping
  # the prefix names for the projects to be generated
301
  LIGHTRING_PROJECT_PREFIX="LightRing"
302
  POWERMANAGEMENT_PROJECT_PREFIX="PowerManagement"
303
  DIWHEELDRIVE_PROJECT_PREFIX="DiWheelDrive"
304 69661903 Thomas Schöpping
305 4cce70a8 Thomas Schöpping
  printf "\n"
306 69661903 Thomas Schöpping
307 4cce70a8 Thomas Schöpping
  ##############################################################################
308
  ###   SETUP                                                                ###
309
  ##############################################################################
310
311
  # move to the project root directory
312
  cd $QTCREATOR_FILES_PATH
313
314
  for ARG in ${ARG_LIST[@]}; do
315
    case $ARG in
316 69661903 Thomas Schöpping
317 4cce70a8 Thomas Schöpping
      ##########################################################################
318
      ###   CLEAN STEP                                                       ###
319
      ##########################################################################
320 69661903 Thomas Schöpping
321 4cce70a8 Thomas Schöpping
      $CLEAN_FLAG)
322
        printf "removing project files..."
323 69661903 Thomas Schöpping
324 4cce70a8 Thomas Schöpping
        # 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
329
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
334
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
339
340
        printf "\tdone\n"
341
        ;;
342
343
      ##########################################################################
344
      ###   WIPE STEP                                                        ###
345
      ##########################################################################
346
347
      $WIPE_FLAG)
348
        printf "removing .user project files..."
349
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
354
355
        printf "\tdone\n"
356
        ;;
357
358
      ##########################################################################
359
      ###   LIGHTRING SETUP                                                  ###
360
      ##########################################################################
361
362
      $LIGHTRING_FLAG)
363
        printf "creating project files for ${LIGHTRING_PROJECT_PREFIX} (STM32F103RET6)..."
364
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
369
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
375
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
380
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
385
386
        printf "\tdone\n"
387
        ;;
388
389
      ##########################################################################
390
      ###   POWERMANAGEMENT SETUP                                            ###
391
      ##########################################################################
392
393
      $POWERMANAGEMENT_FLAG)
394
        printf "creating project files for ${POWERMANAGEMENT_PROJECT_PREFIX} (STM32F405RGT6)..."
395
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
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
406
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
411
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
417
        printf "\tdone\n"
418
        ;;
419
420
      ##########################################################################
421
      ###   DIWHEELDRIVE SETUP                                               ###
422
      ##########################################################################
423
424
      $DIWHEELDRIVE_FLAG)
425
        printf "creating project files for ${DIWHEELDRIVE_PROJECT_PREFIX} (STM32F103RET6)..."
426
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
431
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
437
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
442
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
447
448
        printf "\tdone\n"
449
        ;;
450
451
    esac
452
  done
453
fi
454 69661903 Thomas Schöpping
455 4cce70a8 Thomas Schöpping
################################################################################
456
###   OUTRO                                                                  ###
457
################################################################################