summarylogtreecommitdiffstats
path: root/libmali-wrapper
blob: 9d2756e430e9cc8f7a901d0f34bbaba32cfc89de (plain)
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
#!/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")
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
    ;;
  *)
    TARGET=x11-gbm
    ;;
esac
if [[ -z "$1" ]]; then
  echo "ERROR: No program given"
  exit 1
fi

LIBMALI=/usr/lib/"%MODEL%/${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' ]]; 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