Skip to content

Commit

Permalink
qb: Add a function to find executables in the $PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
orbea committed Nov 21, 2017
1 parent d980336 commit b744f2a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 4 additions & 4 deletions qb/qb.comp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion qb/qb.system.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -26,4 +47,3 @@ if [ -e /etc/lsb-release ]; then
fi

echo "Checking operating system ... $OS ${DISTRO}"

0 comments on commit b744f2a

Please sign in to comment.