Repository navigation
Expand file tree
/
Copy pathactivate-env
More file actions
113 lines (105 loc) · 4.01 KB
/
Copy pathactivate-env
File metadata and controls
113 lines (105 loc) · 4.01 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
_tdo_devkit_activate() {
local root platform compiler previous_root remaining segment cleaned separator more
# Keep activation's working state out of the caller, even on failure.
unset -f _tdo_devkit_activate
root=$(
if [ -n "${BASH_VERSION:-}" ]; then
filepath=$BASH_SOURCE
elif [ -n "${ZSH_VERSION:-}" ]; then
filepath=${(%):-%x}
elif [ -n "${KSH_VERSION:-}" ]; then
filepath=${.sh.file}
elif [ "${0##*/}" = dash ]; then
filepath=$(lsof -p $$ -Fn | tail -n 1)
filepath=${filepath#n}
else
filepath=$0
fi
filepath=$(readlink -f "$filepath") || exit 1
CDPATH= cd -P -- "$(dirname "$filepath")" && pwd -P
) || {
echo "Error: Activation failed. Cannot locate the DevKit installation." >&2
return 1
}
platform=linux
case "${MSYSTEM:-}:${OSTYPE:-}" in
?*:*|*:*msys*) platform=win ;;
esac
compiler="$root/bin/compiler/$platform/armcc"
if [ "$platform" = win ]; then
compiler="$compiler.exe"
fi
if [ ! -f "$compiler" ] || [ ! -x "$compiler" ]; then
echo "Error: Activation failed. Compiler is missing or not executable: $compiler." >&2
return 1
fi
if [ ! -d "$root/bin/tools/$platform" ] ||
[ ! -d "$root/bin/buildtools/$platform" ]; then
echo "Error: Activation failed. DevKit tool or buildtool directory is missing." >&2
return 1
fi
previous_root=${_TDO_DEVKIT_ACTIVE_ROOT:-${TDO_DEVKIT_PATH:-}}
remaining=${PATH-}
cleaned=
separator=
# Split explicitly so empty entries, spaces, and wildcard characters survive.
while :; do
case "$remaining" in
*:*) segment=${remaining%%:*}; remaining=${remaining#*:}; more=1 ;;
*) segment=$remaining; more= ;;
esac
case "$segment" in
"$root/bin/compiler/$platform"|"$root/bin/tools/$platform"|"$root/bin/buildtools/$platform")
;;
"$previous_root/bin/compiler/linux"|"$previous_root/bin/tools/linux"|"$previous_root/bin/buildtools/linux"|"$previous_root/bin/compiler/win"|"$previous_root/bin/tools/win"|"$previous_root/bin/buildtools/win")
if [ -z "$previous_root" ]; then
cleaned="$cleaned$separator$segment"
separator=:
fi
;;
*)
cleaned="$cleaned$separator$segment"
separator=:
;;
esac
[ -n "$more" ] || break
done
PATH="$root/bin/buildtools/$platform:$root/bin/tools/$platform:$root/bin/compiler/$platform${separator:+:$cleaned}"
TDO_DEVKIT_PATH=$root
_TDO_DEVKIT_ACTIVE_ROOT=$root
_TDO_DEVKIT_ACTIVE_PLATFORM=$platform
export PATH TDO_DEVKIT_PATH
deactivate-env() {
local root platform remaining segment cleaned separator more
if [ -z "${_TDO_DEVKIT_ACTIVE_ROOT:-}" ]; then
echo "3DO development environment not activated."
return 1
fi
root=$_TDO_DEVKIT_ACTIVE_ROOT
platform=$_TDO_DEVKIT_ACTIVE_PLATFORM
remaining=${PATH-}
cleaned=
separator=
while :; do
case "$remaining" in
*:*) segment=${remaining%%:*}; remaining=${remaining#*:}; more=1 ;;
*) segment=$remaining; more= ;;
esac
case "$segment" in
"$root/bin/compiler/$platform"|"$root/bin/tools/$platform"|"$root/bin/buildtools/$platform")
;;
*)
cleaned="$cleaned$separator$segment"
separator=:
;;
esac
[ -n "$more" ] || break
done
PATH=$cleaned
export PATH
unset TDO_DEVKIT_PATH _TDO_DEVKIT_ACTIVE_ROOT _TDO_DEVKIT_ACTIVE_PLATFORM
echo "3DO development environment deactivated."
}
echo "3DO development environment activated. Run 'deactivate-env' to deactivate."
}
_tdo_devkit_activate