pantry/projects/tea.xyz/gx/cc/ld

57 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
set -e
if test -z "$PKGX_DIR"
then
echo 'PKGX_DIR 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
}
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
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
# 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 "$PKGX_DIR"