-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_setup.sh
executable file
·140 lines (108 loc) · 2.71 KB
/
build_setup.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
set -e
PROJ_NAME=$1
TARGET=$2
CHIP=$3
echo TARGET=$TARGET
if [ x"$TARGET" = x"" ]; then
exit 1
fi
echo PROJ_NAME=$PROJ_NAME
echo TARGET=$TARGET
echo CHIP=$CHIP
TOP_DIR=$(dirname "$0")
echo $TOP_DIR
echo "Start board build_setup ..."
MORROR=0
IDF_GITEE_TOOLS_PATH=${TOP_DIR}/esp-gitee-tools
IDF_PATH=${TOP_DIR}/esp-idf
IDF_TOOLS_PATH=${TOP_DIR}/.espressif
export IDF_PATH
export IDF_TOOLS_PATH
PYTHON_CMD="python3"
function get_country_code()
{
echo "get_country_code ..."
if command -v python3 &>/dev/null; then
PYTHON_CMD=python3
elif command -v python &>/dev/null && python --version | grep -q '^Python 3'; then
PYTHON_CMD=python
else
echo "Python 3 is not installed."
exit 1
fi
MORROR=$(${PYTHON_CMD} ${TOP_DIR}/tools/get_conutry.py)
}
function enable_mirror()
{
get_country_code
if [ x"$MORROR" = x"1" ]; then
echo "enable mirror"
if [ ! -d ${IDF_GITEE_TOOLS_PATH} ]; then
echo "clone esp-gitee-tools"
git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git ${IDF_GITEE_TOOLS_PATH}
fi
# enable mirror
bash ${IDF_GITEE_TOOLS_PATH}/jihu-mirror.sh set
fi
}
function disable_mirror()
{
if [ x"$MORROR" = x"1" ]; then
echo "disable mirror"
bash ${IDF_GITEE_TOOLS_PATH}/jihu-mirror.sh unset
fi
}
function download_esp_idf()
{
echo "download esp-idf ..."
git clone --recursive https://github.com/espressif/esp-idf -b v5.2.1 --depth=1 ${IDF_PATH}
if [ $? -ne 0 ]; then
return 1
fi
return 0
}
function download_esp_idf_tools()
{
echo "download esp-idf-tools ..."
cd ${IDF_PATH}
git submodule update --init --recursive
cd -
if [ x"$MORROR" = x"1" ]; then
bash ${IDF_GITEE_TOOLS_PATH}/install.sh ${IDF_PATH}
else
bash ${IDF_PATH}/install.sh all
fi
}
if [ ! -d ${IDF_PATH} ]; then
echo "IDF_PATH is empty"
enable_mirror
download_esp_idf
if [ $? -ne 0 ]; then
echo "git clone esp-idf failed ..."
exit 1
else
download_esp_idf_tools
fi
fi
if [ ! -d ${IDF_TOOLS_PATH} ] || [ ! -d ${IDF_TOOLS_PATH}/tools ];then
echo "IDF_TOOLS_PATH is empty ..."
enable_mirror
download_esp_idf_tools
fi
if [ x"$CHIP" = x"esp32" ]; then
TOOLCHAIN_PATH=${IDF_TOOLS_PATH}/tools/xtensa-esp-elf
elif [ x"$CHIP" = x"esp32c3" ]; then
TOOLCHAIN_PATH=${IDF_TOOLS_PATH}/tools/riscv32-esp-elf
else
echo "Target $TARGET not support"
exit 1
fi
if [ ! -d ${TOOLCHAIN_PATH} ]; then
echo "TOOLCHAIN_PATH is empty ..."
enable_mirror
download_esp_idf_tools
fi
disable_mirror
echo "Run build setup success ..."
exit 0