-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·111 lines (88 loc) · 2.67 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
R=`pwd`
VCUBE_DIR=$(dirname `realpath $0`)
source "$VCUBE_DIR/env.sh"
# ---------------------------------------------------------------------------------------------------------------------
function add_target
{
local TARGET="$1"
local PACKAGE="$2"
# remove 'STR32' prefix and make lowercase
local TARGET_NAME=`echo "${TARGET:5}" | tr '[:upper:]' '[:lower:]'`
# try to shorten name
local FILE_NAME="${TARGET_NAME::-2}-$PACKAGE"
test -f "$DIR_VC_TARGETS/$FILE_NAME" &&
FILE_NAME="${TARGET_NAME}-$PACKAGE"
echo "$TARGET" > "$DIR_VC_TARGETS/$FILE_NAME"
}
function explode_variants
{
local TARGET="$1"
local PACKAGE="$2"
# prepare template and variant list
local NAME_TEMPLATE=`echo "$TARGET" | sed -e 's+[(][^)]*[)]+@+'`
local VARIANTS=`echo "$TARGET" | grep -Po '\([^\)]+\)' | tr -d '(),'`
VARIANTS="${VARIANTS//-}"
# make variants
for (( i=0; i<${#VARIANTS}; i++ )); do
TARGET=`echo "$NAME_TEMPLATE" | sed -e "s+@+${VARIANTS:$i:1}+"`
add_target "$TARGET" "$PACKAGE"
done
}
function process_xml
{
local XML_FILE="$1"
local TARGET=`basename "$XML_FILE" .xml`
local PACKAGE=`cat "$XML_FILE" | grep -Po '(?<=Package=")[A-Z]+' | tr '[:upper:]' '[:lower:]'`
if echo "$TARGET" | grep '(' > /dev/null; then
explode_variants "$TARGET" "$PACKAGE"
else
add_target "$TARGET" "$PACKAGE"
fi
}
function copy_or_link
{
local CMD="$1"
local FILE_NAME="$2"
! test -f "$R/$FILE_NAME" && ! test -L "$R/$FILE_NAME" &&
$CMD "$VCUBE_DIR/$FILE_NAME" "$R/$FILE_NAME"
}
# ---------------------------------------------------------------------------------------------------------------------
# install folder
DIR_OUTPUT="$R/build"
VC_INSTALL="$DIR_OUTPUT/vcube-install"
! test -d "$VC_INSTALL" &&
mkdir -p "$VC_INSTALL"
# env for makefile
MK_ENV="$VC_INSTALL/env.mk"
! test -f "$MK_ENV"
{
echo "PATH_VCUBE = $VCUBE_DIR" > "$MK_ENV"
echo "PATH_CUBE_MX = $PATH_CUBE_MX" >> "$MK_ENV"
echo "PATH_CUBE_PROG = $PATH_CUBE_PROG" >> "$MK_ENV"
}
# mcu targets
DIR_VC_TARGETS="$VC_INSTALL/targets"
! test -d "$DIR_VC_TARGETS" &&
{
echo "Installing targets..."
mkdir -p "$DIR_VC_TARGETS"
for f in $PATH_CUBE_MX_FOLDER/db/mcu/STM32*.xml; do
process_xml "$f"
done
}
copy_or_link "cp" ".gitignore"
copy_or_link "cp" ".clang-format"
copy_or_link "ln -s -r" "Makefile"
copy_or_link "cp" "build.conf.mk"
# version control
! git describe > /dev/null 2>&1 &&
git tag 0.0.0 --message='Welcome to VanillaCube'
# hello world
DIR_SRC="$R/src"
! test -d "$DIR_SRC" &&
{
mkdir -p "$DIR_SRC"
cp "$VCUBE_DIR/examples/blink_led/main.cpp" "$DIR_SRC"
}
exit 0