-
Notifications
You must be signed in to change notification settings - Fork 2
/
pelf_linker
executable file
·86 lines (73 loc) · 2.02 KB
/
pelf_linker
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
#!/bin/sh
# Initialize variables
PELF_BINDIRS=""
PELF_LIBDIRS=""
# Function to concatenate existing directories from *_binDir environment variables into PELF_BINDIRS
concatenate_bindirs() {
# Find all environment variables ending with _binDir
vars="$(env | grep ".*_binDir=" | cut -f 1 -d '=')"
for v in $vars; do
# Get the value of the variable
eval "vval=\$$v"
# Save the current IFS and change it to handle colon-separated paths
old_ifs="$IFS"
IFS=":"
# Loop through each path in the variable
for dir in $vval; do
# Check if the directory exists
if [ -d "$dir" ]; then
# Append to PELF_BINDIRS if the directory exists
if [ -z "$PELF_BINDIRS" ]; then
PELF_BINDIRS="$dir"
else
PELF_BINDIRS="$PELF_BINDIRS:$dir"
fi
fi
done
# Restore the original IFS
IFS="$old_ifs"
done
# Print the concatenated PELF_BINDIRS
if [ -z "$1" ]; then
echo "PELF_BINDIRS=\"$PELF_BINDIRS\""
fi
}
# Function to concatenate existing directories from *_libDir environment variables into PELF_LIBDIRS
concatenate_libdirs() {
# Find all environment variables ending with _libDir
vars="$(env | grep ".*_libDir=" | cut -f 1 -d '=')"
for v in $vars; do
# Get the value of the variable
eval "vval=\$$v"
# Save the current IFS and change it to handle colon-separated paths
old_ifs="$IFS"
IFS=":"
# Loop through each path in the variable
for dir in $vval; do
# Check if the directory exists
if [ -d "$dir" ]; then
# Append to PELF_LIBDIRS if the directory exists
if [ -z "$PELF_LIBDIRS" ]; then
PELF_LIBDIRS="$dir"
else
PELF_LIBDIRS="$PELF_LIBDIRS:$dir"
fi
fi
done
# Restore the original IFS
IFS="$old_ifs"
done
# Print the concatenated PELF_LIBDIRS
if [ -z "$1" ]; then
echo "PELF_LIBDIRS=\"$PELF_LIBDIRS\""
fi
}
# Call the functions
concatenate_bindirs "$1"
concatenate_libdirs "$1"
if [ "$1" = "--export" ]; then
export PELF_LIBDIRS="$PELF_LIBDIRS"
export PELF_BINDIRS="$PELF_BINDIRS"
else
LD_LIBRARY_PATH="$PELF_LIBDIRS" PATH="$PATH:$PELF_BINDIRS" "$@"
fi