-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·392 lines (347 loc) · 15.1 KB
/
configure
File metadata and controls
executable file
·392 lines (347 loc) · 15.1 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#!/bin/bash
#---------------------------------------------------------------
# Copyright (C) 2008-2025, inx limited, UK.
# All Rights Reserved.
# You may use, distribute and modify this code under the terms
# of the LGPLv3 license. You should have received a copy of the
# LGPLv3 (GNU LESSER GENERAL PUBLIC LICENSE Version 3) license
# with this file. If not, please visit
# <https://www.gnu.org/licenses/lgpl-3.0.txt>
#---------------------------------------------------------------
source ./scripts/build-function-library/colour.sh
if [ -z "$_CONFIGURE_REENTRY" ]; then
echo "--------------------------------------------------------------------"
echo
heading "inxware runtime software build configuration utilities"
echo
fi
# Build the target list array (used by no-arg menu and numeric selection)
_targets=()
while IFS= read -r t; do
_targets+=("$t")
done < <(ls --hide "*.mk" --hide "*TEMPLATE*" ./target/platform/ | sort)
# Resolve a numeric argument to a target name
_resolve_target() {
local arg="$1"
if [[ "$arg" =~ ^[0-9]+$ ]] && [ "$arg" -ge 1 ] && [ "$arg" -le "${#_targets[@]}" ]; then
echo "${_targets[$((arg-1))]}"
else
echo "$arg"
fi
}
if [ ! -n "${1}" ] ; then
echo "Select a target platform to configure, or type its name:"
echo
# Show current target if configured
CURRENT=""
if [ -e ./TARGET.cfg ]; then
source ./TARGET.cfg
CURRENT="$TARGET"
fi
local_i=1
for t in "${_targets[@]}"; do
if [ "$t" = "$CURRENT" ]; then
printf " ${TXT_FG_BRIGHT_CYAN}%3d) %s <-- current${TXT_RESET}\n" "$local_i" "$t"
else
printf " %3d) %s\n" "$local_i" "$t"
fi
local_i=$((local_i + 1))
done
printf " ${TXT_FG_GREY} 0) exit without changes${TXT_FG}\n"
echo
if [ -n "$CURRENT" ]; then
echo "Current target: ${TXT_FG_BRIGHT_CYAN}${CURRENT}${TXT_FG}"
else
echo "${TXT_FG_YELLOW}No target currently configured.${TXT_FG}"
fi
echo -n "Enter number, target name, or ${TXT_FG_WHITE}/${TXT_FG} to search (${TXT_FG_WHITE}0${TXT_FG}/${TXT_FG_WHITE}x${TXT_FG} to exit): "
read -r REPLY
if [ -z "$REPLY" ] || [ "$REPLY" = "0" ] || [ "$REPLY" = "q" ] || [ "$REPLY" = "Q" ] || [ "$REPLY" = "x" ] || [ "$REPLY" = "X" ]; then
exit 0
fi
# Search mode: user typed '/' (with optional search term after it)
if [[ "$REPLY" = /* ]]; then
SEARCH="${REPLY:1}"
if [ -z "$SEARCH" ]; then
echo -n "Search platforms: "
read -r SEARCH
fi
_filtered=()
for t in "${_targets[@]}"; do
if [[ "$t" == *"$SEARCH"* ]]; then
_filtered+=("$t")
fi
done
if [ "${#_filtered[@]}" -eq 0 ]; then
echo "${TXT_FG_YELLOW}No platforms match '${SEARCH}'.${TXT_FG}"
_CONFIGURE_REENTRY=1 exec "$0"
fi
echo
echo "Platforms matching '${TXT_FG_WHITE}${SEARCH}${TXT_FG}':"
echo
local_j=1
for t in "${_filtered[@]}"; do
if [ "$t" = "$CURRENT" ]; then
printf " ${TXT_FG_BRIGHT_CYAN}%3d) %s <-- current${TXT_RESET}\n" "$local_j" "$t"
else
printf " %3d) %s\n" "$local_j" "$t"
fi
local_j=$((local_j + 1))
done
printf " ${TXT_FG_GREY} 0) back${TXT_FG}\n"
echo
echo -n "Enter number or target name (${TXT_FG_WHITE}0${TXT_FG}/${TXT_FG_WHITE}x${TXT_FG} to exit): "
read -r REPLY2
if [ -z "$REPLY2" ] || [ "$REPLY2" = "0" ] || [ "$REPLY2" = "q" ] || [ "$REPLY2" = "Q" ] || [ "$REPLY2" = "x" ] || [ "$REPLY2" = "X" ]; then
_CONFIGURE_REENTRY=1 exec "$0"
fi
# Resolve numeric selection within filtered list, or fall back to name
if [[ "$REPLY2" =~ ^[0-9]+$ ]] && [ "$REPLY2" -ge 1 ] && [ "$REPLY2" -le "${#_filtered[@]}" ]; then
SELECTED="${_filtered[$((REPLY2-1))]}"
else
SELECTED="$REPLY2"
fi
_CONFIGURE_REENTRY=1 exec "$0" "$SELECTED"
fi
# Re-run configure with the resolved target
SELECTED=$(_resolve_target "$REPLY")
_CONFIGURE_REENTRY=1 exec "$0" "$SELECTED"
fi
if [ "$1" = "help" -o "$1" = "-h" -o "$1" = "-help" -o "$1" = "--help" ]; then
echo "Utilities to help build eRT for your target:"
echo
echo " ${TXT_FG_WHITE}./configure ${TXT_FG_GREEN}: show numbered list of platform targets and select interactively (type / to search)."
echo " ${TXT_FG_WHITE}./configure TARGET ${TXT_FG_GREEN}: select a platform target by name (this is a sticky configuration)."
echo " ${TXT_FG_WHITE}./configure NUMBER ${TXT_FG_GREEN}: select a platform target by number from the list."
echo " ${TXT_FG_WHITE}./configure -new NEW_TARGET ${TXT_FG_GREEN}: create a new platform target and configure it.
${TXT_FG_WHITE}./configure -clone ${TXT_FG_GREEN}: clone the current platform target to a new name (Dockerfile becomes a symlink to original)."
echo " ${TXT_FG_WHITE}./configure -edit ${TXT_FG_GREEN}: edit ./target/platform/${TARGET} with nano (exit to return here)."
echo " ${TXT_FG_WHITE}./configure -debug ${TXT_FG_GREEN}: run the selected target on this host with GDB (if the host supports it)."
echo " ${TXT_FG_WHITE}./configure -run ${TXT_FG_GREEN}: run the selected target on this host (if the host supports it)."
echo " ${TXT_FG_WHITE}./configure -edit-dockerfile ${TXT_FG_GREEN}: change the docker configuration (if the selected target has a Dockerfile)."
echo " ${TXT_FG_WHITE}./configure -edit-dockerimagename ${TXT_FG_GREEN}: change the name of the docker image used to build the selected target."
echo " ${TXT_FG_WHITE}./configure -diff ${TXT_FG_GREEN}: compare current platform config folder against another using meld."
echo " ${TXT_FG_WHITE}./configure -deploy user@ip ${TXT_FG_GREEN}: deploy staged TARGET_TREES to a device via SSH, kill any running ehs, sync /opt/ehs, and start ehs."
echo " ${TXT_FG_WHITE}./configure -pushd ${TXT_FG_GREEN}: change directory to the ../TARGET_TREES staging directory (exit to return here)."
echo " ${TXT_FG_WHITE}./configure -pushd-config ${TXT_FG_GREEN}: change directory to ./target/platform/${TARGET} (exit to return here)."
echo
echo "Use the following to see build commands and utilities:"
echo
echo " ${TXT_FG_WHITE}make help"
echo
exit 0
fi
if [ "$1" = "-new" ]; then
if [ ! -d ./target/platform/${2}/config.mk ]; then
if [ "${2}" = "" ]; then
err "Please provide a target name. (see ./configure -help )"
exit 1
fi
mkdir ./target/platform/${2} || exit 1
cp ./target/platform/TEMPLATE/* ./target/platform/${2}/
# set TARGET.cfg
./configure ${2}
# prompt the user to edit it!
./configure -edit
else
err "./target/platform/${2}/config.mk already exists. Please choose again".
exit 1
fi
exit
fi
if [ "$1" = "-clone" ]; then
source ./TARGET.cfg
echo "Cloning current target: ${TXT_FG_WHITE}${TARGET}${TXT_FG}"
echo "Enter new target name (edit the name, then press Enter):"
read -e -i "$TARGET" -r NEW_NAME
if [ -z "$NEW_NAME" ]; then
err "New target name cannot be empty."
exit 1
fi
if [ "$NEW_NAME" = "$TARGET" ]; then
err "New target name must differ from the original (${TARGET})."
exit 1
fi
if [ -d "./target/platform/${NEW_NAME}" ]; then
err "Target [${NEW_NAME}] already exists. Please choose a unique name."
exit 1
fi
cp -r "./target/platform/${TARGET}" "./target/platform/${NEW_NAME}" || exit 1
# Replace any Dockerfile in the clone with a symlink back to the original
if [ -e "./target/platform/${NEW_NAME}/Dockerfile" ] || [ -L "./target/platform/${NEW_NAME}/Dockerfile" ]; then
rm "./target/platform/${NEW_NAME}/Dockerfile"
ln -s "../${TARGET}/Dockerfile" "./target/platform/${NEW_NAME}/Dockerfile"
echo " Dockerfile -> symlink to ${TXT_FG_WHITE}../target/platform/${TARGET}/Dockerfile${TXT_FG}"
fi
echo "Cloned ${TXT_FG_WHITE}${TARGET}${TXT_FG} -> ${TXT_FG_WHITE}${NEW_NAME}${TXT_FG}."
_CONFIGURE_REENTRY=1 exec "$0" "${NEW_NAME}" -edit
fi
# The tree is configured entirely by this reference to config files in target/platform/*
if [ "$1" = "-edit" ]; then
source ./TARGET.cfg
nano ./target/platform/${TARGET}/config.mk
exit
fi
if [ "$1" = "-edit-dockerfile" ]; then
source ./TARGET.cfg
nano ./target/platform/${TARGET}/Dockerfile
exit
fi
if [ "$1" = "-edit-dockerimagename" ]; then
source ./TARGET.cfg
nano ./target/platform/${TARGET}/Dockerimagename
exit
fi
if [ "$1" = "-debug" ]; then
source ./TARGET.cfg
pushd ../TARGET_TREES/ehs_env-${TARGET}/bin
export DISPLAY=:0.0
gdb -ex "set substitute-path inxwware ../" -ex "run" ./ehs.exe
popd
exit
fi
if [ "$1" = "-run" ]; then
source ./TARGET.cfg
pushd ../TARGET_TREES/ehs_env-${TARGET}/bin
export DISPLAY=:0.0
./ehs.exe
popd
exit
fi
if [ "$1" = "-pushd" ]; then
source ./TARGET.cfg
echo "Changing directory, type exit to return"
pushd ../TARGET_TREES/ehs_env-${TARGET}/
bash
exit
fi
if [ "$1" = "-pushd-config" ]; then
source ./TARGET.cfg
echo "Changing directory, type ${TXT_FG_WHITE}exit${TXT_FG} to return"
pushd ./target/platform/${TARGET}/
bash
exit
fi
if [ "$1" = "-deploy" ]; then
./target/envbuildscripts/deploy.sh "$2"
exit
fi
if [ "$1" = "-diff" ]; then
source ./TARGET.cfg
echo "Current target: ${TXT_FG_WHITE}${TARGET}${TXT_FG}"
_diff_pick() {
local -n _list=$1
local local_i=1
for t in "${_list[@]}"; do
if [ "$t" = "$TARGET" ]; then
printf " ${TXT_FG_BRIGHT_CYAN}%3d) %s <-- current${TXT_RESET}\n" "$local_i" "$t"
else
printf " %3d) %s\n" "$local_i" "$t"
fi
local_i=$((local_i + 1))
done
printf " ${TXT_FG_GREY} 0) exit${TXT_FG}\n"
echo
echo -n "Enter number, target name, or ${TXT_FG_WHITE}/${TXT_FG} to search (${TXT_FG_WHITE}0${TXT_FG}/${TXT_FG_WHITE}x${TXT_FG} to exit): "
read -r _DIFF_REPLY
if [ -z "$_DIFF_REPLY" ] || [ "$_DIFF_REPLY" = "0" ] || [ "$_DIFF_REPLY" = "q" ] || [ "$_DIFF_REPLY" = "Q" ] || [ "$_DIFF_REPLY" = "x" ] || [ "$_DIFF_REPLY" = "X" ]; then
exit 0
fi
if [[ "$_DIFF_REPLY" = /* ]]; then
SEARCH="${_DIFF_REPLY:1}"
if [ -z "$SEARCH" ]; then
echo -n "Search platforms: "
read -r SEARCH
fi
_filtered=()
for t in "${_list[@]}"; do
[[ "$t" == *"$SEARCH"* ]] && _filtered+=("$t")
done
if [ "${#_filtered[@]}" -eq 0 ]; then
echo "${TXT_FG_YELLOW}No platforms match '${SEARCH}'.${TXT_FG}"
echo
_diff_pick "$1"
return
fi
echo
echo "Platforms matching '${TXT_FG_WHITE}${SEARCH}${TXT_FG}':"
echo
local local_j=1
for t in "${_filtered[@]}"; do
if [ "$t" = "$TARGET" ]; then
printf " ${TXT_FG_BRIGHT_CYAN}%3d) %s <-- current${TXT_RESET}\n" "$local_j" "$t"
else
printf " %3d) %s\n" "$local_j" "$t"
fi
local_j=$((local_j + 1))
done
printf " ${TXT_FG_GREY} 0) back${TXT_FG}\n"
echo
echo -n "Enter number or target name (${TXT_FG_WHITE}0${TXT_FG}/${TXT_FG_WHITE}x${TXT_FG} to exit): "
read -r _DIFF_REPLY2
if [ -z "$_DIFF_REPLY2" ] || [ "$_DIFF_REPLY2" = "0" ] || [ "$_DIFF_REPLY2" = "q" ] || [ "$_DIFF_REPLY2" = "Q" ] || [ "$_DIFF_REPLY2" = "x" ] || [ "$_DIFF_REPLY2" = "X" ]; then
echo
_diff_pick "$1"
return
fi
if [[ "$_DIFF_REPLY2" =~ ^[0-9]+$ ]] && [ "$_DIFF_REPLY2" -ge 1 ] && [ "$_DIFF_REPLY2" -le "${#_filtered[@]}" ]; then
OTHER="${_filtered[$((_DIFF_REPLY2-1))]}"
else
OTHER="$_DIFF_REPLY2"
fi
elif [[ "$_DIFF_REPLY" =~ ^[0-9]+$ ]] && [ "$_DIFF_REPLY" -ge 1 ] && [ "$_DIFF_REPLY" -le "${#_list[@]}" ]; then
OTHER="${_list[$((${_DIFF_REPLY}-1))]}"
else
OTHER="$_DIFF_REPLY"
fi
}
echo "Select a target to compare against:"
echo
_diff_pick _targets
meld ./target/platform/${TARGET}/ ./target/platform/${OTHER}/
exit
fi
## Otherwise assume we are changing to a new specified configuration
# Resolve numeric target selection (e.g. ./configure 5)
if [[ "$1" =~ ^[0-9]+$ ]]; then
RESOLVED=$(_resolve_target "$1")
if [ "$RESOLVED" = "$1" ]; then
err "Number $1 is out of range (1-${#_targets[@]}). Run ./configure to see the list."
exit 1
fi
# Re-run with the resolved name so all subsequent logic uses the target string
_CONFIGURE_REENTRY=1 exec "$0" "$RESOLVED" "${@:2}"
fi
# Check we have the config
if [ ! -d ./target/platform/$1 ]; then
err "TARGET [$1] does not exist."
echo
echo "Run ${TXT_FG_WHITE}./configure${TXT_FG} to see the numbered list of available targets,"
echo "or create a new platform with ${TXT_FG_WHITE}./configure -new <name>${TXT_FG}"
exit 1
fi
# The tree is configured entirely by this reference to config files in target/platform/*
if [ "$2" = "-edit" ]; then
command echo "TARGET=$1" > ./TARGET.cfg
nano ./target/platform/${1}/config.mk
TARGET=$1
elif [ "$1" != "" ]; then
command echo "TARGET=$1" > ./TARGET.cfg
TARGET=$1
fi
echo "--------------------------------------------------------------------"
echo
echo "The build tree is configured for target ${TXT_FG_WHITE}$1${TXT_FG}."
echo
echo "Next Steps & Options:"
echo " ${TXT_FG_WHITE}make prepdeps ${TXT_FG}# Clone or update dependency repositories ${TXT_FG_GREEN}-------------> Start here to checkout dependencise (e.g. for your first non-githib CI build)."
echo " ${TXT_FG_WHITE}make all_docker ${TXT_FG}# Make the eRT runtime binary in configured docker ${TXT_FG_GREEN}----> Start here if you have already checked out the dependencies, as above."
echo " ${TXT_FG_WHITE}make -j 8 all ${TXT_FG}# Build eRT directly on your host environment ${TXT_FG_GREEN}---------> Configure your host to build or interactive docker shell?"
echo " ${TXT_FG_WHITE}make targetenv ${TXT_FG}# Assemble all rutime dependencies in the staging directory: ${TXT_FG_WHITE}../TARGET_TREES/ehs-env-$1"
echo " ${TXT_FG_WHITE}make targetpack ${TXT_FG}# Package the staging directory into a target specific package"
echo
echo "Ready to build ${TXT_FG_WHITE}${TARGET}..."
echo
echo " See ${TXT_FG_WHITE}make help${TXT_FG} for detailed more build, packaging and maintenace options."
echo
echo "--------------------------------------------------------------------"