Statistics
| Branch: | Revision:

amiro-apps / tools / ide / QtCreator / QtCreatorSetup.sh @ ec600fee

History | View | Annotate | Download (28.946 KB)

1 b1f38b27 Thomas Schöpping
################################################################################
2
# AMiRo-Apps is a collection of applications and configurations for the        #
3
# Autonomous Mini Robot (AMiRo).                                               #
4 6d4ba740 Thomas Schöpping
# Copyright (C) 2018..2020  Thomas Schöpping et al.                            #
5 b1f38b27 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
#!/bin/bash
25
26 8dab1768 Thomas Schöpping
# load library
27
source "$(dirname ${BASH_SOURCE[0]})/../../bash/setuplib.sh"
28 b1f38b27 Thomas Schöpping
29
### 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
function printWelcomeText {
37
  printf "######################################################################\n"
38
  printf "#                                                                    #\n"
39
  printf "#                  Welcome to the QtCreator setup!                   #\n"
40
  printf "#                                                                    #\n"
41
  printf "######################################################################\n"
42
  printf "#                                                                    #\n"
43 6d4ba740 Thomas Schöpping
  printf "# Copyright (c) 2018..2020  Thomas Schöpping                         #\n"
44 b1f38b27 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
}
55
56
### print help #################################################################
57
# Prints a help text to standard out.
58
#
59
# usage:      printHelp
60
# arguments:  n/a
61
# return:     n/a
62
#
63
function printHelp {
64
  printInfo "printing help text\n"
65 21f9c863 Thomas Schöpping
  printf "usage:    $(basename ${BASH_SOURCE[0]}) [-h|--help] [-c|--create=<configuration>] [-d|--delete=<configuration>] [-q|--quit] [--log=<file>]\n"
66 b1f38b27 Thomas Schöpping
  printf "\n"
67
  printf "options:  -h, --help\n"
68
  printf "              Print this help text.\n"
69 21f9c863 Thomas Schöpping
  printf "          -c, --create <configuration>\n"
70
  printf "              Create projects for a single configuration or for all configurations (<configuration>='*').\n"
71
  printf "          -d, --delete <configuration>\n"
72
  printf "              Delete projet files of a single configuration or of all configurations (<configuration>='*').\n"
73 b1f38b27 Thomas Schöpping
  printf "          -q, --quit\n"
74
  printf "              Quit the script.\n"
75
  printf "          --log=<file>\n"
76
  printf "              Specify a log file.\n"
77
}
78
79
### read directory where to create/delete projects #############################
80
# Read the directory where to create/delete project files from user.
81
#
82 2be62ace Thomas Schöpping
# usage:      getProjectsDir <pathvar>
83 b1f38b27 Thomas Schöpping
# arguments:  <pathvar>
84
#                 Variable to store the selected path to.
85
# return:     n/a
86
#
87 2be62ace Thomas Schöpping
function getProjectsDir {
88 b1f38b27 Thomas Schöpping
  local amiroappsdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../)
89
  local input=""
90 21f9c863 Thomas Schöpping
91
  printLog "reading path for project files from user...\n"
92 b1f38b27 Thomas Schöpping
  read -p "Path where to create/delete project files: " -i $amiroappsdir -e input
93
  printLog "user selected path $(realpath $input)\n"
94
  eval $1="$(realpath $input)"
95
}
96
97
### retrieves the ARM-NONE-EABI-GCC include directory ##########################
98
# Retrieves the include directory of the currently set arm-none-eabi-gcc.
99
#
100
# usage:      retrieveGccIncludeDir <path>
101
# arguments:  <path>
102
#                 Variable to store the path to.
103
# return:    0
104
#                 No error or warning occurred.
105
#            -1
106
#                 Error: Command 'arm-none-eabi-gcc' not found.
107 2be62ace Thomas Schöpping
#            -2
108
#                 Error: include directory could not be resolved.
109 b1f38b27 Thomas Schöpping
#
110
function retrieveGccIncludeDir {
111
  local binpath=$(which arm-none-eabi-gcc)
112 2be62ace Thomas Schöpping
  local gccincpath=""
113 21f9c863 Thomas Schöpping
114
  # retrieve binary path or link
115 b1f38b27 Thomas Schöpping
  if [ -z "$binpath" ]; then
116
    printError "command 'arm-none-eabi-gcc' not found\n"
117
    return -1
118
  else 
119
120
    # traverse any links
121
    while [ -L "$binpath" ]; do
122 2be62ace Thomas Schöpping
      binpath=$(realpath $(dirname $binpath)/$(readlink $binpath))
123 b1f38b27 Thomas Schöpping
    done
124
    printInfo "gcc-arm-none-eabi detected: $binpath\n"
125
126
    # return include path
127 2be62ace Thomas Schöpping
    gccincpath=$(realpath $(dirname ${binpath})/../arm-none-eabi/include/)
128
    if [ ! -d "$gccincpath" ]; then
129
      printWarning "$gccincpath does not exist\n"
130
      return -2
131
    else
132
      eval $1="$gccincpath"
133
      return 0
134
    fi
135 b1f38b27 Thomas Schöpping
  fi
136
}
137
138 2be62ace Thomas Schöpping
### detect available configurations ############################################
139
# Detect all avalable configurations.
140 b1f38b27 Thomas Schöpping
#
141 2be62ace Thomas Schöpping
# usage:      detectConfigurations <configurationsarray>
142
# arguments:  <configurationsarray>
143
#                 Array variable to store all detected configurations to.
144
# return:     n/a
145
#
146
function detectConfigurations {
147
  local configs_detected=()
148 21f9c863 Thomas Schöpping
  local configsdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../configurations)
149 2be62ace Thomas Schöpping
150
  # detect all available modules (via directories)
151
  for dir in $(ls -d ${configsdir}/*/); do
152
    configs_detected[${#configs_detected[@]}]=$(basename $dir)
153
  done
154
155
  # set the output variable
156
  eval "$1=(${configs_detected[*]})"
157
}
158
159 21f9c863 Thomas Schöpping
### create project files for a single or for all configurations ################
160
# Create project files for all modules of a single or of all configurations.
161 2be62ace Thomas Schöpping
#
162 21f9c863 Thomas Schöpping
# usage:      createProject <configurations> [-c|--configuration=<configuration>] [-p|--path=<path>] [--gcc=<path>] [-o|--out=<var>] [--gccout=<var>]
163 2be62ace Thomas Schöpping
# arguments:  <configurations>
164
#                 Array containing all configurations available.
165 21f9c863 Thomas Schöpping
#             -c, --configuration <configuration>
166 2be62ace Thomas Schöpping
#                 Name (folder name) of the configuration for which project files shall be generated.
167 21f9c863 Thomas Schöpping
#                 Set <configuration> to '*' in order to generate projects for all available configurations.
168 2be62ace Thomas Schöpping
#             -p, --path <path>
169 b1f38b27 Thomas Schöpping
#                 Path where to create the project files.
170
#             --gcc=<path>
171
#                 Path to the GCC include directory.
172
#             -o, --out <var>
173
#                 Variable to store the path to.
174
#             --gccout=<var>
175
#                 Variable to store the path to the GCC include directory to.
176 2be62ace Thomas Schöpping
#                 If this optional arguments is absent, ths function will ask for user input.
177 b1f38b27 Thomas Schöpping
# return:     0
178
#                 No error or warning occurred.
179 2be62ace Thomas Schöpping
#             1
180
#                 Aborted by user.
181
#             2
182
#                 The selected configuration does not contain any modules.
183
#             -1
184
#                 No configurations available.
185
#             -2
186
#                 The specified <configuration> could not be found.
187
#             -3
188
#                 Parsing the project for the specified configuration failed.
189
#             -4
190
#                 Missing dependencies.
191 b1f38b27 Thomas Schöpping
#
192 21f9c863 Thomas Schöpping
function createProject {
193 2be62ace Thomas Schöpping
  local config=""
194 21f9c863 Thomas Schöpping
  local configs=("${!1}")
195
  local configs2generate=()
196
  local configsdir=$(realpath $(dirname $(realpath ${BASH_SOURCE[0]}))/../../../configurations)
197 b1f38b27 Thomas Schöpping
  local gccincludedir=""
198
  local gccoutvar=""
199 21f9c863 Thomas Schöpping
  local includes=()
200
  local makedir=""
201
  local makedirs=()
202
  local modules=()
203
  local otherargs=()
204
  local outvar=""
205
  local parse_state=""
206
  local projectfiles=()
207
  local projects=()
208
  local projectsdir=""
209
  local quotes="\'\"\´\`\„\“"
210
  local rawout=""
211
  local sourcefile=""
212
  local sourcefiles=()
213
  local userdir=$(pwd)
214
  local userinput=""
215 b1f38b27 Thomas Schöpping
216 2be62ace Thomas Schöpping
  # check dependencies
217
  checkCommands make
218
  if [ $? -ne 0 ]; then
219
    printError "Missing dependencies detected.\n"
220
    return -4
221
  fi
222
223 b1f38b27 Thomas Schöpping
  # parse arguments
224
  while [ $# -gt 0 ]; do
225
    if ( parseIsOption $1 ); then
226
      case "$1" in
227 21f9c863 Thomas Schöpping
        -c=*|--configuration=*)
228 2be62ace Thomas Schöpping
          config="${1#*=}"; shift 1;;
229 21f9c863 Thomas Schöpping
        -c|--configuration)