mirror of
https://github.com/ivabus/pantry
synced 2024-11-23 17:05:07 +03:00
56 lines
1.2 KiB
Bash
Executable file
56 lines
1.2 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
if test -z "$TEA_PREFIX"
|
|
then
|
|
echo 'TEA_PREFIX mysteriously unset' >&2
|
|
exit 1
|
|
fi
|
|
|
|
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
|
|
|
|
return 1
|
|
}
|
|
|
|
# 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
|
|
if __which $(basename "$0") || __which ld; then
|
|
:
|
|
else
|
|
echo 'ld not found in PATH' >&2
|
|
exit 127
|
|
fi
|
|
|
|
# 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
|
|
|
|
exec "$exe" "$@" -rpath "$TEA_PREFIX"
|