qb: Extend check_platform.

This extends the check_platform function to support checking more
than one OS for each feature.

This also adds the match helper function to qb.init.sh to compare
one variable against a list of variables.
This commit is contained in:
orbea 2019-07-12 09:23:36 -07:00
parent cac7e25167
commit 89a8202dc5
2 changed files with 46 additions and 15 deletions

View File

@ -41,3 +41,19 @@ exists()
done
return $v
}
# match:
# Compares a variable against a list of variables
# $1 = variable
# $@ = list of variables
match()
{
var="$1"
shift
for string do
case "$string" in
"$var" ) return 0 ;;
esac
done
return 1
}

View File

@ -82,30 +82,45 @@ check_enabled()
}
# check_platform:
# $1 = OS
# $1 = OS ['OS' or 'OS OS2 OS3', $1 = name]
# $2 = HAVE_$2
# $3 = feature
# $4 = enable feature when true [checked only if non-empty]
# $4 = enable feature when 'true', disable errors with 'user' [checked only if non-empty]
check_platform()
{ tmpval="$(eval "printf %s \"\$HAVE_$2\"")"
[ "$tmpval" = 'no' ] && return 0
error=
newval=
setval="$(eval "printf %s \"\$USER_$2\"")"
if [ "$setval" = 'yes' ]; then
if { [ "$1" != "$OS" ] && [ "${4:-}" = 'true' ]; } ||
{ [ "$1" = "$OS" ] &&
[ "${4:-}" != 'true' ]; }; then
die 1 "Error: $3 not supported for $OS."
for platform in $(printf %s "$1"); do
if [ "$setval" = 'yes' ]; then
if [ "$error" != 'no' ] && [ "${4:-}" != 'user' ] &&
{ { [ "$platform" != "$OS" ] &&
match "${4:-}" true user; } ||
{ [ "$platform" = "$OS" ] &&
! match "${4:-}" true user; }; }; then
error='yes'
elif match "${4:-}" true user; then
error='no'
fi
elif [ "$platform" = "$OS" ]; then
if match "${4:-}" true user; then
newval=yes
break
else
newval=no
fi
elif match "${4:-}" true user; then
newval=auto
fi
elif [ "$1" = "$OS" ]; then
if [ "${4:-}" = 'true' ]; then
eval "HAVE_$2=yes"
else
eval "HAVE_$2=no"
fi
elif [ "${4:-}" = 'true' ]; then
eval "HAVE_$2="
done
if [ "${error}" = 'yes' ]; then
die 1 "Error: $3 not supported for $OS."
else
eval "HAVE_$2=\"${newval:-$tmpval}\""
fi
}