-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibmali-wrapper
83 lines (79 loc) · 2.2 KB
/
libmali-wrapper
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
#!/bin/bash
# Multi-call wrapper for libmali by 7Ji based on https://aur.archlinux.org/cgit/aur.git/tree/libmali?h=linux-radxa-rkbsp5-git
NAME=$(basename "$0")
LIBMALI_PATH=/usr/lib/%MODEL%
if ! [[ "${NAME}" =~ ^libmali* ]]; then
echo "ERROR: Helper script called as $0 (basename ${NAME}), please call it as libmali*"
exit 1
fi
if [[ "${NAME:7:1}" == '-' ]]; then
SUFFIX="${NAME:8}"
else
SUFFIX="${NAME:7}"
fi
case "${SUFFIX}" in
[dD]*)
TARGET=dummy
;;
[gG]*)
TARGET=gbm
;;
[wW]*)
TARGET=wayland-gbm
;;
x11-wayland-gbm)
TARGET=x11-wayland-gbm
;;
[xX]*)
TARGET=x11-gbm
;;
*)
if [[ -d "${LIBMALI_PATH}/x11-wayland-gbm" ]]; then
TARGET=x11-wayland-gbm
elif [[ -d "${LIBMALI_PATH}/wayland-gbm" ]] && [ -n "$WAYLAND_DISPLAY" ]; then
TARGET=wayland-gbm
elif [[ -d "${LIBMALI_PATH}/x11-gbm" ]] && [ -n "$DISPLAY" ]; then
TARGET=x11-gbm
else
echo "ERROR: Failed to lookup libmali or display not initialized."
exit 1
fi
;;
esac
if [[ -z "$1" ]]; then
echo "ERROR: No program given"
exit 1
fi
LIBMALI="${LIBMALI_PATH}/${TARGET}"
if [[ ! -d "${LIBMALI}" ]]; then
echo "ERROR: Failed to lookup libmali at '${LIBMALI}'"
exit 1
fi
if [[ -d '/usr/lib/gl4es' ]]; then
LIBGL_DEEPBIND=0
GL4ES='/usr/lib/gl4es:'
else
LIBGL_DEEPBIND=
GL4ES=
fi
LD_LIBRARY_PATH="${GL4ES}${LIBMALI}:${LD_LIBRARY_PATH}"
if [[ -f '/usr/lib/libdri2to3.so' ]] && [ "$TARGET" != "gbm" ]; then
DRI2TO3='/usr/lib/libdri2to3.so:'
else
DRI2TO3=
fi
LD_PRELOAD="${DRI2TO3}${LD_PRELOAD}"
APP="$(which $1)"
export LIBGL_DEEPBIND LD_LIBRARY_PATH LD_PRELOAD
# linux linker loads the shared libs in the order of 1. RPATH of the elf, then LD_LIBRARY_PATH
# if a binary has RPATH pointed out to /usr/lib, then this causes system GL libraries to load
# in such a case we load the app directly with linker ommitting the rpath of /usr/lib
if /usr/bin/chrpath -l "${APP}" | /usr/bin/grep --quiet '\(/usr\)\?/lib$'; then
echo "Running ${APP} with lib%MODEL%-${TARGET} using linker"
exec /usr/lib/%LD% --inhibit-rpath :/usr/lib "${APP}" "${@:2}"
else
echo "Running ${APP} with lib%MODEL%-${TARGET}"
exec "${APP}" "${@:2}"
fi
echo "ERROR: Failed to execute ${APP}"
exit 1