Skip to content

Commit

Permalink
configure: remove dependency on which
Browse files Browse the repository at this point in the history
This function has an upstream: https://notabug.org/orbea/exists
  • Loading branch information
orbea committed Nov 10, 2023
1 parent 335bb13 commit a12f1ed
Showing 1 changed file with 72 additions and 4 deletions.
76 changes: 72 additions & 4 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,70 @@ set -o errexit
set -o pipefail
set -o nounset

exists ()
{
r=0; cwd="$(pwd)"
while [ $# -gt 0 ]; do
v=1
arg="$1"
shift
case "$arg" in
''|*/ )
:
;;
/* )
if [ -f "$arg" ] && [ -x "$arg" ]; then
printf %s\\n "$arg"
v=0
fi
;;
./* )
if [ -f "$arg" ] && [ -x "$arg" ]; then
pre="$(cd -- "${arg%%/*}/" && pwd)"
printf %s\\n "${pre%/}/$arg"
v=0
fi
;;
*/* )
if [ -f "$arg" ] && [ -x "$arg" ]; then
printf %s\\n "$(cd -- "${arg%%/*}/.." && pwd)/$arg"
v=0
fi
;;
* )
if [ -n "${PATH+x}" ]; then
p=":${PATH:-$cwd}"
while [ "$p" != "${p#*:}" ] && [ -n "${p#*:}" ]; do
p="${p#*:}"
x="${p%%:*}"
z="${x:-$cwd}"
d="${z%/}/$arg"
if [ -f "$d" ] && [ -x "$d" ]; then
case "$d" in
/* )
:
;;
./* )
pre="$(cd -- "${d%/*}/" && pwd)"
d="${pre%/}/$d"
;;
* )
d="$(cd -- "${d%/*}/" && pwd)/$arg"
;;
esac
printf %s\\n "$d"
v=0
break
fi
done
fi
;;
esac
[ $v = 0 ] || r=1
done
return $r
}

fail()
{
echo "${1}"
Expand Down Expand Up @@ -145,12 +209,14 @@ VERSION=$(cat "${SRCDIR}/misc/VERSION")

# Check for a c compiler (mandatory)

CC="$(exists "${CC}")" || CC=""

echo -n "Checking for a C compiler ... "
if [[ ! -x "$(which "${CC}")" ]]; then
if [[ ! -x "${CC}" ]]; then
fail "Error: CC not valid"
else
export CC
which "${CC}" | tee -a config.log
echo "${CC}" | tee -a config.log
fi

echo -n "Checking $(basename "${CC}") can produce executables ... "
Expand Down Expand Up @@ -188,13 +254,15 @@ LIB_CHECK=""

# Check for pkg-config (mandatory)

PKG_CONFIG="$(exists "${PKG_CONFIG}")" || PKG_CONFIG=""

echo -n "Checking for pkg-config ... "
if [[ ! -x "$(which "${PKG_CONFIG}")" ]]; then
if [[ ! -x "${PKG_CONFIG}" ]]; then
fail "Error: PKG_CONFIG not valid"
fi

export PKG_CONFIG
which "${PKG_CONFIG}"
echo "${PKG_CONFIG}"

# Support functions

Expand Down

0 comments on commit a12f1ed

Please sign in to comment.