1
1
#! /bin/sh
2
2
3
+ # If the script is not sourced, the exported variables are not saved
4
+ # in the environment.
5
+ if [ " $( basename -- " $0 " ) " = " export.sh" ]; then
6
+ echo " Please run the script prefixed with a '.' followed by a space to source it." 1>&2
7
+ exit 1
8
+ fi
9
+
3
10
ESP32_GCC_RELEASE=" esp-14.2.0_20241119"
4
11
ESP8266_GCC_RELEASE=" esp-5.2.0_20191018"
5
12
15
22
16
23
TOOLS_PATH=" ${IDF_TOOLS_PATH} /tools"
17
24
25
+ # this function expects the parameters $TOOL, $TOOLS_DIR and $*_VERSION
26
+ export_checks ()
27
+ {
28
+ TOOL=" $1 "
29
+ TOOLS_DIR_INT=" $2 " # internal TOOLS_DIR
30
+ TOOLS_VERSION=" $3 "
31
+
32
+ # create the wildcard expression from the TOOLS_DIR
33
+ TOOLS_DIR_BASE=$( echo " $TOOLS_DIR_INT /bin" | sed " s|/$TOOLS_VERSION /|/[^/]*/|" )
34
+ TOOLS_DIR_IN_PATH=$( echo " $PATH " | grep " ${TOOLS_DIR_INT} " )
35
+
36
+ if [ ! -e " ${TOOLS_DIR_INT} " ]; then
37
+ echo " ${TOOLS_DIR_INT} does not exist - please run"
38
+ echo " \$ {RIOTBASE}/dist/tools/esptools/install.sh $TOOL "
39
+ return 1
40
+ fi
41
+
42
+ echo " $PATH " | tr ' :' ' \n' | while read -r entry; do
43
+ if echo " $entry " | grep -q " ^${TOOLS_DIR_BASE} $" ; then
44
+ if [ " $entry " != " ${TOOLS_DIR_INT} /bin" ]; then
45
+ echo " Warning: PATH contains outdated entry: \" $entry \" ." \
46
+ " Please check your ~/.bashrc or ~/.profile." >&2
47
+ fi
48
+ fi
49
+ done
50
+ unset entry
51
+
52
+ if [ -e " ${TOOLS_DIR_INT} " ] && [ -z " ${TOOLS_DIR_IN_PATH} " ]; then
53
+ echo " Extending PATH by ${TOOLS_DIR_INT} /bin"
54
+ export PATH=" ${TOOLS_DIR_INT} /bin:${PATH} "
55
+
56
+ echo " To make this permanent, add this line to your ~/.bashrc or ~/.profile:"
57
+ echo PATH=" \$ PATH:${TOOLS_DIR_INT} /bin"
58
+ fi
59
+
60
+ unset TOOL
61
+ unset TOOLS_DIR_INT
62
+ unset TOOLS_VERSION
63
+ unset TOOLS_DIR_IN_PATH
64
+
65
+ return 0
66
+ }
67
+
18
68
export_arch ()
19
69
{
20
70
case $1 in
@@ -36,35 +86,18 @@ export_arch()
36
86
esac
37
87
38
88
TOOLS_DIR=" ${TOOLS_PATH} /${TARGET_ARCH} /${ESP_GCC_RELEASE} /${TARGET_ARCH} "
39
- TOOLS_DIR_IN_PATH=$( echo " $PATH " | grep " ${TOOLS_DIR} " )
40
-
41
- if [ ! -e " ${TOOLS_DIR} " ]; then
42
- echo " ${TOOLS_DIR} does not exist - please run"
43
- echo " \$ {RIOTBASE}/dist/tools/esptools/install.sh $1 "
44
- return
45
- fi
46
-
47
- if [ -e " ${TOOLS_DIR} " ] && [ -z " ${TOOLS_DIR_IN_PATH} " ]; then
48
- echo " Extending PATH by ${TOOLS_DIR} /bin"
49
- export PATH=" ${TOOLS_DIR} /bin:${PATH} "
50
- fi
51
-
52
- echo " To make this permanent, add this line to your ~/.bashrc or ~/.profile:"
53
- echo PATH=" \$ PATH:${TOOLS_DIR} /bin"
54
-
89
+ export_checks " $1 " " $TOOLS_DIR " " $ESP_GCC_RELEASE "
55
90
unset TOOLS_DIR
56
91
}
57
92
58
93
export_openocd ()
59
94
{
60
95
TOOLS_DIR=" ${TOOLS_PATH} /openocd-esp32/${ESP32_OPENOCD_VERSION} "
61
- TOOLS_DIR_IN_PATH=$( echo " $PATH " | grep " ${TOOLS_DIR} " )
62
96
OPENOCD_DIR=" ${TOOLS_DIR} /openocd-esp32"
63
97
64
- if [ -e " ${OPENOCD_DIR} " ] && [ -z " ${TOOLS_DIR_IN_PATH} " ]; then
65
- echo " Extending PATH by ${TOOLS_DIR} /bin"
66
- export PATH=" ${OPENOCD_DIR} /bin:${PATH} "
67
- export OPENOCD=" ${OPENOCD_DIR} /bin/openocd -s ${OPENOCD_DIR} /share/openocd/scripts"
98
+ export_checks " openocd" " $OPENOCD_DIR " " $ESP32_OPENOCD_VERSION "
99
+ if [ $? -eq 0 ]; then
100
+ export OPENOCD=" ${OPENOCD_DIR} /bin/openocd -s ${OPENOCD_DIR} /share/openocd/scripts"
68
101
fi
69
102
70
103
unset TOOLS_DIR
@@ -107,13 +140,7 @@ export_qemu()
107
140
fi
108
141
109
142
TOOLS_DIR=" ${TOOLS_PATH} /${QEMU_ARCH} /${ESP32_QEMU_VERSION} /qemu"
110
- TOOLS_DIR_IN_PATH=$( echo " $PATH " | grep " ${TOOLS_DIR} " )
111
-
112
- if [ -e " ${TOOLS_DIR} " ] && [ -z " ${TOOLS_DIR_IN_PATH} " ]; then
113
- echo " Extending PATH by ${TOOLS_DIR} /bin"
114
- export PATH=" ${TOOLS_DIR} /bin:${PATH} "
115
- fi
116
-
143
+ export_checks " qemu $1 " " $TOOLS_DIR " " $ESP32_QEMU_VERSION "
117
144
unset TOOLS_DIR
118
145
}
119
146
@@ -132,13 +159,7 @@ export_gdb()
132
159
esac
133
160
134
161
TOOLS_DIR=" ${TOOLS_PATH} /${GDB_ARCH} /${GDB_VERSION} /${GDB_ARCH} "
135
- TOOLS_DIR_IN_PATH=$( echo " $PATH " | grep " ${TOOLS_DIR} " )
136
-
137
- if [ -e " ${TOOLS_DIR} " ] && [ -z " ${TOOLS_DIR_IN_PATH} " ]; then
138
- echo " Extending PATH by ${TOOLS_DIR} /bin"
139
- export PATH=" ${TOOLS_DIR} /bin:${PATH} "
140
- fi
141
-
162
+ export_checks " gdb $1 " " $TOOLS_DIR " " $GDB_VERSION "
142
163
unset TOOLS_DIR
143
164
}
144
165
@@ -170,7 +191,7 @@ elif [ "$1" = "gdb" ]; then
170
191
elif [ " $1 " = " openocd" ]; then
171
192
export_openocd
172
193
elif [ " $1 " = " qemu" ]; then
173
- export_qemu $2
194
+ export_qemu " $2 "
174
195
else
175
196
export_arch " $1 "
176
197
fi
0 commit comments