-
Notifications
You must be signed in to change notification settings - Fork 1
/
pelf_linker
executable file
·59 lines (51 loc) · 1.63 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
#!/bin/sh
# Function to concatenate all *_bindir environment variables into PELF_BINDIRS
vval=""
PELF_BINDIRS=""
PELF_LIBDIRS=""
concatenate_bindirs() {
# Target any variable ending with _bindir
vars="$(env | grep ".*_binDir=" | cut -f 1 -d '=')"
for v in $vars; do
# Use eval to get the value of the variable
eval "vval=\$$v"
# Append the value to PELF_BINDIRS, ensuring to add a colon if it's not the first entry
if [ -z "$PELF_BINDIRS" ]; then
PELF_BINDIRS="$vval"
else
PELF_BINDIRS="$PELF_BINDIRS:$vval"
fi
done
# Print the concatenated PELF_BINDIRS
if [ -z "$1" ]; then
echo "PELF_BINDIRS=\"$PELF_BINDIRS\""
fi
}
# Function to concatenate all *_bindir environment variables into PELF_LIBDIRS
concatenate_libdirs() {
# Target any variable ending with _bindir
vars="$(env | grep ".*_libDir=" | cut -f 1 -d '=')"
for v in $vars; do
# Use eval to get the value of the variable
eval "vval=\$$v"
# Append the value to PELF_LIBDIRS, ensuring to add a colon if it's not the first entry
if [ -z "$PELF_LIBDIRS" ]; then
PELF_LIBDIRS="$vval"
else
PELF_LIBDIRS="$PELF_LIBDIRS:$vval"
fi
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