2023-06-12 21:49:44 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
2022-10-17 20:45:32 +03:00
|
|
|
|
2023-06-09 16:32:36 +03:00
|
|
|
if test -z "$TEA_PREFIX"
|
|
|
|
then
|
|
|
|
echo 'TEA_PREFIX mysteriously unset' >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-06-12 21:49:44 +03:00
|
|
|
DIR=$(dirname "$0")
|
|
|
|
IFS=: read -r -a PATHS <<< "$PATH"
|
|
|
|
|
|
|
|
__which() {
|
|
|
|
for dir in "${PATHS[@]}"; do
|
|
|
|
if test "$dir" == "$DIR"; then
|
|
|
|
: # no fork bombs thanks
|
|
|
|
elif [ -L "$dir/$1" ]; then
|
|
|
|
# no fork bombs thanks
|
|
|
|
foo="$(realpath "$dir/$1")"
|
|
|
|
foo="$(basename "$foo")"
|
|
|
|
if [ "$foo" != "tea" ]; then
|
|
|
|
exe="$dir/$1"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
elif [ -x "$dir/$1" ]; then
|
|
|
|
exe="$dir/$1"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
2022-10-17 20:45:32 +03:00
|
|
|
|
2023-06-12 21:49:44 +03:00
|
|
|
return 1
|
|
|
|
}
|
2022-11-09 21:26:10 +03:00
|
|
|
|
|
|
|
# If we can find our specific name, e.g. `lld`,
|
|
|
|
# passthrough to that
|
|
|
|
# Otherwise, fallback to `ld`
|
|
|
|
# NB: this might not have the right invocations, sometimes;
|
|
|
|
# (invoking `ld` as `lld64.ld`) watch for those potential cases
|
2023-06-12 21:49:44 +03:00
|
|
|
if __which $(basename "$0") || __which ld; then
|
|
|
|
:
|
2022-11-09 22:47:21 +03:00
|
|
|
else
|
|
|
|
echo 'ld not found in PATH' >&2
|
|
|
|
exit 127
|
2022-10-27 20:29:16 +03:00
|
|
|
fi
|
|
|
|
|
2023-06-09 16:32:36 +03:00
|
|
|
# At a minimum, `ld` will complain if you mix the `-r` and `-rpath` flags,
|
|
|
|
# so if any argument to this script is `-r`, we just pass through without
|
|
|
|
# additions.
|
|
|
|
for word in "$@"; do
|
|
|
|
if test "$word" = "-r"; then
|
|
|
|
exec "$exe" "$@"
|
|
|
|
fi
|
|
|
|
done
|
2023-06-12 21:49:44 +03:00
|
|
|
|
2023-06-09 16:32:36 +03:00
|
|
|
exec "$exe" "$@" -rpath "$TEA_PREFIX"
|