amiro-blt / ide / QtCreator / QtCreatorSetup.sh @ 69661903
History | View | Annotate | Download (13.8 KB)
1 |
#!/bin/bash |
---|---|
2 |
|
3 |
############################################################################### |
4 |
### HELPER FUNCTIONS ### |
5 |
############################################################################### |
6 |
|
7 |
#------------------------------------------------------------------------------ |
8 |
# toAbsolutePath $1 [$2] |
9 |
# |
10 |
# Makes a given path absolute and either echos the result or stores it in the |
11 |
# specified variable. |
12 |
# arguments: |
13 |
# $1: the path to be converted |
14 |
# $2: a variable to store the resulting path [optiional] |
15 |
function toAbsolutePath { |
16 |
# the path that shall be converted if required |
17 |
TARGET_PATH=$1 |
18 |
|
19 |
# store the path where the script was called from |
20 |
ORIGIN_PATH="${PWD}/" |
21 |
|
22 |
# check, whether the target is a directory or not |
23 |
if [ -d $TARGET_PATH ]; then |
24 |
cd $TARGET_PATH |
25 |
# special case: the target is the root directory |
26 |
if [ $TARGET_PATH = "/" ]; then |
27 |
ABSOLUTE_PATH="${PWD}" |
28 |
else |
29 |
ABSOLUTE_PATH="${PWD}/" |
30 |
fi |
31 |
else |
32 |
cd $(dirname $TARGET_PATH) |
33 |
ABSOLUTE_PATH="${PWD}/$(basename $TARGET_PATH)" |
34 |
fi |
35 |
cd $ORIGIN_PATH |
36 |
|
37 |
# return the result |
38 |
if [ $# -gt 1 ]; then |
39 |
eval $2="$ABSOLUTE_PATH" |
40 |
else |
41 |
echo $ABSOLUTE_PATH |
42 |
fi |
43 |
|
44 |
# cleanup |
45 |
unset TARGET_PATH |
46 |
unset ORIGIN_PATH |
47 |
unset ABSOLUTE_PATH |
48 |
} |
49 |
#------------------------------------------------------------------------------ |
50 |
|
51 |
#------------------------------------------------------------------------------ |
52 |
# getRelativePath $1 $2 [$3] |
53 |
# |
54 |
# Computes the relative path from one to another location. |
55 |
# The result is then either stored in a specified variable, or just echoed. |
56 |
# arguments: |
57 |
# $1: the path to start from |
58 |
# If this is not a directory, only the path will be used |
59 |
# $2: the target location |
60 |
# $3: a variable to store the resulting path [optional] |
61 |
function getRelativePath { |
62 |
# make start and target location absolute |
63 |
START_PATH=$(toAbsolutePath $1) |
64 |
if [ ! -d $START_PATH ]; then |
65 |
START_PATH="$(dirname $START_PATH)/" |
66 |
fi |
67 |
TARGET_PATH=$(toAbsolutePath $2) |
68 |
|
69 |
# initialize the common prefix and the relative path from START_PATH to TARGET_PATH |
70 |
COMMON_PREFIX=$START_PATH |
71 |
RELATIVE_PATH="./" |
72 |
# while the common prefix is no substring of the target path |
73 |
while [ "${TARGET_PATH#$COMMON_PREFIX}" == "$TARGET_PATH" ]; do |
74 |
read |
75 |
# reduce the common prefix and record the relative path |
76 |
COMMON_PREFIX="$(dirname $COMMON_PREFIX)/" |
77 |
RELATIVE_PATH="../$RELATIVE_PATH" |
78 |
# special case: if only root is the common prefix, remove the just appended '/' |
79 |
if [ $COMMON_PREFIX == "//" ]; then |
80 |
COMMON_PREFIX="/" |
81 |
fi |
82 |
done |
83 |
|
84 |
# if the relative path is more than just the current directory, cut off the trailing './' |
85 |
if [ ! $RELATIVE_PATH == "./" ]; then |
86 |
RELATIVE_PATH=${RELATIVE_PATH::-2} |
87 |
fi |
88 |
|
89 |
# compute the unique part of the target path |
90 |
UNIQUE_POSTFIX=${TARGET_PATH#$COMMON_PREFIX} |
91 |
|
92 |
# append the unique postfix to the relative path |
93 |
RELATIVE_PATH=$RELATIVE_PATH$UNIQUE_POSTFIX |
94 |
|
95 |
# return the result |
96 |
if [ $# -gt 2 ]; then |
97 |
eval $3="$RELATIVE_PATH" |
98 |
else |
99 |
echo $RELATIVE_PATH |
100 |
fi |
101 |
|
102 |
# clean up |
103 |
unset START_PATH |
104 |
unset TARGET_PATH |
105 |
unset COMMON_PREFIX |
106 |
unset RELATIVE_PATH |
107 |
unset UNIQUE_POSTFIX |
108 |
} |
109 |
#------------------------------------------------------------------------------ |
110 |
|
111 |
#------------------------------------------------------------------------------ |
112 |
# printHelp |
113 |
# |
114 |
# Prnts a help text, how to use this script |
115 |
function printHelp { |
116 |
echo -e "The following commands are available:" |
117 |
echo -e "" |
118 |
echo -e " help - Prints this help text." |
119 |
echo -e " all - Creates a project for each of the AMiRo base modules." |
120 |
echo -e " clean - Deletes all files created by this script." |
121 |
echo -e " wipe - In addittion to 'clean', the .user files created by QtCreator are deleted as well." |
122 |
echo -e "" |
123 |
echo -e "Note: This script does not create a project for the host application." |
124 |
echo -e " Since the host application uses CMAKE, QtCreator can import it directly." |
125 |
} |
126 |
|
127 |
#------------------------------------------------------------------------------ |
128 |
|
129 |
|
130 |
|
131 |
############################################################################### |
132 |
### INTRO ### |
133 |
############################################################################### |
134 |
|
135 |
echo "-------------------------------------------------------------------------------" |
136 |
echo "" |
137 |
echo "Setup to create QtCreator projects" |
138 |
echo "==================================" |
139 |
echo "" |
140 |
|
141 |
############################################################################### |
142 |
### INITIALIZATION ### |
143 |
############################################################################### |
144 |
|
145 |
# the current user dir |
146 |
USER_DIR="${PWD}/" |
147 |
|
148 |
# the directory containing this script file |
149 |
toAbsolutePath $(dirname ${BASH_SOURCE[0]}) SCRIPT_DIR |
150 |
|
151 |
# the root directory of the project |
152 |
toAbsolutePath ${SCRIPT_DIR}../../ PROJECT_ROOT_DIR |
153 |
|
154 |
# the location where to create the QtCreator files |
155 |
QTCREATOR_FILES_PATH=${PROJECT_ROOT_DIR} |
156 |
|
157 |
# the include path for GCC specific headers |
158 |
ARM_NONE_EABI_GCC_BIN=$(which arm-none-eabi-gcc) |
159 |
while [ -L $ARM_NONE_EABI_GCC_BIN ]; do |
160 |
ARM_NONE_EABI_GCC_BIN=$(readlink $ARM_NONE_EABI_GCC_BIN) |
161 |
done |
162 |
toAbsolutePath "$(dirname $ARM_NONE_EABI_GCC_BIN)/../arm-none-eabi/include/" ARM_NONE_EABI_GCC_INCLUDE_PATH |
163 |
|
164 |
# a common path for all projects |
165 |
COMMON_SOURCE_INCLUDE_PATH=${PROJECT_ROOT_DIR}Target/Source |
166 |
|
167 |
# the paths to the individual projects |
168 |
POWERMANAGEMENT_PROJECT_ROOT_PATH=${PROJECT_ROOT_DIR}Target/Demo/ARMCM4_STM32F405_Power_Management_GCC/Boot |
169 |
DIWHEELDRIVE_PROJECT_ROOT_PATH=${PROJECT_ROOT_DIR}Target/Demo/ARMCM3_STM32F103_DiWheelDrive_GCC/Boot |
170 |
LIGHTRING_PROJECT_ROOT_PATH=${PROJECT_ROOT_DIR}Target/Demo/ARMCM3_STM32F103_LightRing_GCC/Boot |
171 |
|
172 |
# some prefixes for the project files |
173 |
POWERMANAGEMENT_PROJECT_PREFIX="PowerManagement" |
174 |
DIWHEELDRIVE_PROJECT_PREFIX="DiWheelDrive" |
175 |
LIGHTRING_PROJECT_PREFIX="LightRing" |
176 |
|
177 |
# evaluate user arguments |
178 |
COMMAND="" |
179 |
shopt -s nocasematch |
180 |
if [ $# == 0 ]; then |
181 |
COMMAND="help" |
182 |
else |
183 |
case $1 in |
184 |
"help"|"h") |
185 |
COMMAND="help" |
186 |
;; |
187 |
"all"|"a") |
188 |
COMMAND="all" |
189 |
;; |
190 |
"clean"|"c") |
191 |
COMMAND="clean" |
192 |
;; |
193 |
"wipe"|"w") |
194 |
COMMAND="wipe" |
195 |
;; |
196 |
*) |
197 |
COMMAND="unknown" |
198 |
;; |
199 |
esac |
200 |
fi |
201 |
|
202 |
############################################################################### |
203 |
### SETUP ### |
204 |
############################################################################### |
205 |
|
206 |
cd $QTCREATOR_FILES_PATH |
207 |
|
208 |
case $COMMAND in |
209 |
|
210 |
############################################################################# |
211 |
### HELP CASE ### |
212 |
############################################################################# |
213 |
"help") |
214 |
printHelp |
215 |
;; |
216 |
|
217 |
############################################################################# |
218 |
### CLEAN / WIPE CASE ### |
219 |
############################################################################# |
220 |
"clean"|"wipe") |
221 |
echo -n "removing project files..." |
222 |
|
223 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.includes |
224 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.files |
225 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.config |
226 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.creator |
227 |
|
228 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.includes |
229 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.files |
230 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.config |
231 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.creator |
232 |
|
233 |
rm ${LIGHTRING_PROJECT_PREFIX}.includes |
234 |
rm ${LIGHTRING_PROJECT_PREFIX}.files |
235 |
rm ${LIGHTRING_PROJECT_PREFIX}.config |
236 |
rm ${LIGHTRING_PROJECT_PREFIX}.creator |
237 |
|
238 |
echo -e "\tdone" |
239 |
|
240 |
if [ $COMMAND == "wipe" ]; then |
241 |
echo -n "removing .user project files..." |
242 |
if [ -f ${POWERMANAGEMENT_PROJECT_PREFIX}.creator.user ]; then |
243 |
rm ${POWERMANAGEMENT_PROJECT_PREFIX}.creator.user |
244 |
fi |
245 |
if [ -f ${DIWHEELDRIVE_PROJECT_PREFIX}.creator.user ]; then |
246 |
rm ${DIWHEELDRIVE_PROJECT_PREFIX}.creator.user |
247 |
fi |
248 |
if [ -f ${LIGHTRING_PROJECT_PREFIX}.creator.user ]; then |
249 |
rm ${LIGHTRING_PROJECT_PREFIX}.creator.user |
250 |
fi |
251 |
echo -e "\tdone" |
252 |
fi |
253 |
;; |
254 |
|
255 |
############################################################################# |
256 |
### CREATE CASE ### |
257 |
############################################################################# |
258 |
"all") |
259 |
########################################################################### |
260 |
### Create PowerManagement Project ### |
261 |
########################################################################### |
262 |
echo -n "creating project files for ${POWERMANAGEMENT_PROJECT_PREFIX} (STM32F405RGT6)..." |
263 |
|
264 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
265 |
find $ARM_NONE_EABI_GCC_INCLUDE_PATH -type d > ${POWERMANAGEMENT_PROJECT_PREFIX}.includes |
266 |
find $COMMON_SOURCE_INCLUDE_PATH -type d | grep -v "ARMCM3_STM32" >> ${POWERMANAGEMENT_PROJECT_PREFIX}.includes |
267 |
find $POWERMANAGEMENT_PROJECT_ROOT_PATH -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${POWERMANAGEMENT_PROJECT_PREFIX}.includes |
268 |
|
269 |
# generate a file that specifies all files |
270 |
echo -n "" > ${POWERMANAGEMENT_PROJECT_PREFIX}.files |
271 |
for path in `cat ${POWERMANAGEMENT_PROJECT_PREFIX}.includes`; do |
272 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${POWERMANAGEMENT_PROJECT_PREFIX}.files |
273 |
done |
274 |
|
275 |
# generate a default project configuration file if none exists so far |
276 |
if [ ! -f ${POWERMANAGEMENT_PROJECT_PREFIX}.config ]; then |
277 |
echo -e "// Add predefined macros for your project here. For example:\n// #define YOUR_CONFIGURATION belongs here\n" > ${POWERMANAGEMENT_PROJECT_PREFIX}.config |
278 |
fi |
279 |
|
280 |
# generate a default .creator file if none exists so far |
281 |
if [ ! -f ${POWERMANAGEMENT_PROJECT_PREFIX}.creator ]; then |
282 |
echo -e "[general]\n" > ${POWERMANAGEMENT_PROJECT_PREFIX}.creator |
283 |
fi |
284 |
|
285 |
echo -e "\tdone" |
286 |
|
287 |
########################################################################### |
288 |
### Create DiWheelDrive Project ### |
289 |
########################################################################### |
290 |
echo -n "creating project files for ${DIWHEELDRIVE_PROJECT_PREFIX} (STM32F103RET6)..." |
291 |
|
292 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
293 |
find $ARM_NONE_EABI_GCC_INCLUDE_PATH -type d > ${DIWHEELDRIVE_PROJECT_PREFIX}.includes |
294 |
find $COMMON_SOURCE_INCLUDE_PATH -type d | grep -v "ARMCM4_STM32" >> ${DIWHEELDRIVE_PROJECT_PREFIX}.includes |
295 |
find $DIWHEELDRIVE_PROJECT_ROOT_PATH -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${DIWHEELDRIVE_PROJECT_PREFIX}.includes |
296 |
|
297 |
# generate a file that specifies all files |
298 |
echo -n "" > ${DIWHEELDRIVE_PROJECT_PREFIX}.files |
299 |
for path in `cat ${DIWHEELDRIVE_PROJECT_PREFIX}.includes`; do |
300 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${DIWHEELDRIVE_PROJECT_PREFIX}.files |
301 |
done |
302 |
|
303 |
# generate a default project configuration file if none exists so far |
304 |
if [ ! -f ${DIWHEELDRIVE_PROJECT_PREFIX}.config ]; then |
305 |
echo -e "// Add predefined macros for your project here. For example:\n// #define YOUR_CONFIGURATION belongs here\n" > ${DIWHEELDRIVE_PROJECT_PREFIX}.config |
306 |
fi |
307 |
|
308 |
# generate a default .creator file if none exists so far |
309 |
if [ ! -f ${DIWHEELDRIVE_PROJECT_PREFIX}.creator ]; then |
310 |
echo -e "[general]\n" > ${DIWHEELDRIVE_PROJECT_PREFIX}.creator |
311 |
fi |
312 |
|
313 |
echo -e "\tdone" |
314 |
|
315 |
########################################################################### |
316 |
### Create LightRing Project ### |
317 |
########################################################################### |
318 |
echo -n "creating project files for ${LIGHTRING_PROJECT_PREFIX} (STM32F103RET6)..." |
319 |
|
320 |
# generate a file that contains all subdirectories as includes (but ignore hidden and documentation directories) |
321 |
find $ARM_NONE_EABI_GCC_INCLUDE_PATH -type d > ${LIGHTRING_PROJECT_PREFIX}.includes |
322 |
find $COMMON_SOURCE_INCLUDE_PATH -type d | grep -v "ARMCM4_STM32" >> ${LIGHTRING_PROJECT_PREFIX}.includes |
323 |
find $LIGHTRING_PROJECT_ROOT_PATH -type d | grep -v "uip\|fatfs\|ethernetlib\|cmd\|ide" >> ${LIGHTRING_PROJECT_PREFIX}.includes |
324 |
|
325 |
# generate a file that specifies all files |
326 |
echo -n "" > ${LIGHTRING_PROJECT_PREFIX}.files |
327 |
for path in `cat ${LIGHTRING_PROJECT_PREFIX}.includes`; do |
328 |
find $path -maxdepth 1 -type f \( ! -iname ".*" \) | grep -v "/arm-none-eabi/" | grep -E ".*(\.h|\.c|\.x)$" >> ${LIGHTRING_PROJECT_PREFIX}.files |
329 |
done |
330 |
|
331 |
# generate a default project configuration file if none exists so far |
332 |
if [ ! -f ${LIGHTRING_PROJECT_PREFIX}.config ]; then |
333 |
echo -e "// Add predefined macros for your project here. For example:\n// #define YOUR_CONFIGURATION belongs here\n" > ${LIGHTRING_PROJECT_PREFIX}.config |
334 |
fi |
335 |
|
336 |
# generate a default .creator file if none exists so far |
337 |
if [ ! -f ${LIGHTRING_PROJECT_PREFIX}.creator ]; then |
338 |
echo -e "[general]\n" > ${LIGHTRING_PROJECT_PREFIX}.creator |
339 |
fi |
340 |
|
341 |
echo -e "\tdone" |
342 |
|
343 |
;; |
344 |
|
345 |
############################################################################# |
346 |
### ERROR CASE ### |
347 |
############################################################################# |
348 |
*) |
349 |
echo "ERROR: invalid argument!" |
350 |
echo "" |
351 |
printHelp |
352 |
;; |
353 |
|
354 |
esac |
355 |
|
356 |
############################################################################### |
357 |
### OUTRO ### |
358 |
############################################################################### |
359 |
|
360 |
echo "" |
361 |
echo "-------------------------------------------------------------------------------" |
362 |
|