-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDo
executable file
·117 lines (103 loc) · 3.72 KB
/
Do
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
#!/bin/bash
# This script will find a suitable tclsh executable and call the launch.tcl file with it.
# Array of: IDE executable names, the paths to the tclsh wrt to them (including the tclsh executable name), the LD_LIBRARY_PATH for tclsh, optionally the TCL_LIB path (where init.tcl is located)
# The separator must be comma and space and the path separator in the second element must be : with no spaces
# Get the directory containing the script
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
executables=(
"tclsh, ./tclsh, ., "
"vivado, unwrapped/lnx64.o/tclsh8.5:unwrapped/lnx32.o/tclsh8.5:unwrapped/lnx64.o/tclsh8.6:unwrapped/lnx32.o/tclsh8.6, ../lib/lnx64.o/:../lib/lnx32.o/, ../tps/tcl/tcl8.5/:../tps/tcl/tcl8.6/"
"quartus, ./tclsh, ../linux64:../linux32, "
"planAhead, lin64/tclsh:lin32/tclsh, ../lib/lin64/:../lib/lin32/, "
"libero, ../bin64/acttclsh:../bin32/acttclsh, ../lib64/:../lib32/, ../lib64/tcl8.5/:../lib64/tcl8.6/"
"diamond, ../../tcltk/bin/tclsh, ../../tcltk/lib, ../../tcltk/lib/tcl8.5/:../../tcltk/lib/tcl8.6/:"
)
# Function to find the directory of an executable in the PATH
find_executable_dir() {
local executable="$1"
local IFS=':'
for dir in $PATH; do
local path="$dir/$executable"
if [ -x "$path" ]; then
echo "$(dirname "$path")"
return 0
fi
done
return 1
}
# Function to normalise a path
normalise_path() {
local path="$1"
if [[ "$(uname)" == "Darwin" ]]; then
# Install greadlink on mac with `brew install coreutils`
echo $(greadlink -m $path)
else
echo $(readlink -m $path)
fi
#an alternative could be realpath -m
}
if [[ "$HOG_LOGGER" == "ENABLED" ]]; then
source ${script_dir}/Other/Logger.sh
Logger_Init "$*"
fi
hog_dir="$(cd "$(dirname "$0")" && pwd)"
found=0
found_lib=0
# Loop through the executables array
for executable in "${executables[@]}"; do
# Split the executable and additional path
IFS=', ' read -r exe_name exe_paths lib_paths tcl_libs <<< "$executable"
# Find the directory path of the executable
executable_dir=""
if executable_dir=$(find_executable_dir "$exe_name"); then
IFS=":" read -ra exe_paths <<< "$exe_paths"
for exe_path in "${exe_paths[@]}"; do
executable_path=$(normalise_path "$executable_dir/$exe_path")
if [ -x "$executable_path" ]; then
#Setting LD_LIBRARY_PATH now
IFS=":" read -ra lib_paths <<< "$lib_paths"
for lib_path in "${lib_paths[@]}"; do
library_path=$(normalise_path "$executable_dir/$lib_path")
if [ -d "$library_path" ]; then
found_lib=1
break
fi
done
# Optionally we want to set TCL_LIB
IFS=":" read -ra tcl_libs <<< "$tcl_libs"
for tcl_lib in "${tcl_libs[@]}"; do
tcl_library=$(normalise_path "$executable_dir/$tcl_lib")
if [ -d "$tcl_library" ]; then
found_tcl_lib=1
break
fi
done
if [ "$found_lib" == 1 ]; then
found=1
break
fi
fi
done
fi
if [ "$found" == 1 ]; then
break
fi
done
if [ "$found" == 1 ]; then
export LD_LIBRARY_PATH=$library_path:$LD_LIBRARY_PATH
if [ "$found_tcl_lib" == 1 ]; then
#This is where init.tcl is located to avoid the initial warning when running tclsh
export TCL_LIBRARY=$tcl_library
fi
if [[ "$HOG_LOGGER" == "ENABLED" ]]; then
Logger $executable_path $hog_dir/Tcl/launch.tcl "$@"
Hog_exit
else
$executable_path $hog_dir/Tcl/launch.tcl "$@"
exit $?
fi
# Hog_exit
else
echo "Error: No IDE executable found in PATH. You need an IDE in your PATH to use Hog." >&2
exit 1
fi