1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-08 12:15:49 +00:00

qb: Add a function to find executables in the $PATH

This commit is contained in:
orbea 2017-11-19 11:46:38 -08:00
parent d980336a80
commit b744f2a2c9
2 changed files with 25 additions and 5 deletions

View File

@ -14,7 +14,7 @@ cc_works=0
if [ "$CC" ]; then
"$CC" -o "$TEMP_EXE" "$TEMP_C" >/dev/null 2>&1 && cc_works=1
else
for CC in $(printf %s "$(which ${CROSS_COMPILE}gcc ${CROSS_COMPILE}cc ${CROSS_COMPILE}clang 2>/dev/null)") ''; do
for CC in $(exists ${CROSS_COMPILE}gcc ${CROSS_COMPILE}cc ${CROSS_COMPILE}clang) ''; do
"$CC" -o "$TEMP_EXE" "$TEMP_C" >/dev/null 2>&1 && cc_works=1 && break
done
fi
@ -44,7 +44,7 @@ cxx_works=0
if [ "$CXX" ]; then
"$CXX" -o "$TEMP_EXE" "$TEMP_CXX" >/dev/null 2>&1 && cxx_works=1
else
for CXX in $(printf %s "$(which ${CROSS_COMPILE}g++ ${CROSS_COMPILE}c++ ${CROSS_COMPILE}clang++ 2>/dev/null)") ''; do
for CXX in $(exists ${CROSS_COMPILE}g++ ${CROSS_COMPILE}c++ ${CROSS_COMPILE}clang++) ''; do
"$CXX" -o "$TEMP_EXE" "$TEMP_CXX" >/dev/null 2>&1 && cxx_works=1 && break
done
fi
@ -67,7 +67,7 @@ fi
if [ "$OS" = "Win32" ]; then
echobuf="Checking for windres"
if [ -z "$WINDRES" ]; then
WINDRES=$(which ${CROSS_COMPILE}windres)
WINDRES=$(exists ${CROSS_COMPILE}windres)
[ "$WINDRES" ] || die 1 "$echobuf ... Not found. Exiting."
fi
echo "$echobuf ... $WINDRES"
@ -76,7 +76,7 @@ fi
[ -n "$PKG_CONF_PATH" ] || {
PKG_CONF_PATH="none"
for p in $(which "${CROSS_COMPILE}pkg-config" 2>/dev/null) ''; do
for p in $(exists "${CROSS_COMPILE}pkg-config") ''; do
[ -n "$p" ] && {
PKG_CONF_PATH=$p;
break;

View File

@ -1,3 +1,24 @@
exists() # checks executables listed in $@ against the $PATH
{
v=1
while [ "$#" -gt 0 ]; do
arg="$1"
shift 1
case "$arg" in ''|*/) continue ;; esac
x="${arg##*/}"
z="${arg%/*}"
[ ! -f "$z/$x" ] || [ ! -x "$z/$x" ] && [ "$z/$x" = "$arg" ] && continue
[ "$x" = "$z" ] && [ -x "$z/$x" ] && [ ! -f "$arg" ] && z=
p=":$z:$PATH"
while [ "$p" != "${p#*:}" ]; do
p="${p#*:}"
d="${p%%:*}"
{ [ -f "$d/$x" ] && [ -x "$d/$x" ] && \
{ printf %s\\n "$d/$x"; v=0; break; }; } || :
done
done
return "$v"
}
if [ -n "$CROSS_COMPILE" ]; then
case "$CROSS_COMPILE" in
@ -26,4 +47,3 @@ if [ -e /etc/lsb-release ]; then
fi
echo "Checking operating system ... $OS ${DISTRO}"