configure: simplify options parsing

This commit simplifies options parsing moving all the code not related to
parsing out of the case statement.

- The conditional shift after the assignments is moved right after the
  case, reducing code duplication.
- The semantic checks on the LIBBPF_FORCE value is moved after the loop
  like we already did for INCLUDE and LIBBPF_DIR.
- Finally, the loop condition is changed to check remaining arguments, thus
  making it possible to get rid of the null string case break.

As a bonus, now the help message states that on or off should follow
--libbpf_force

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: David Ahern <dsahern@kernel.org>
This commit is contained in:
Andrea Claudi 2021-10-14 10:50:52 +02:00 committed by David Ahern
parent c330d09794
commit 99245d1741
1 changed files with 18 additions and 19 deletions

37
configure vendored
View File

@ -485,12 +485,12 @@ usage()
{ {
cat <<EOF cat <<EOF
Usage: $0 [OPTIONS] Usage: $0 [OPTIONS]
--include_dir <dir> Path to iproute2 include dir --include_dir <dir> Path to iproute2 include dir
--libbpf_dir <dir> Path to libbpf DESTDIR --libbpf_dir <dir> Path to libbpf DESTDIR
--libbpf_force Enable/disable libbpf by force. Available options: --libbpf_force <on|off> Enable/disable libbpf by force. Available options:
on: require link against libbpf, quit config if no libbpf support on: require link against libbpf, quit config if no libbpf support
off: disable libbpf probing off: disable libbpf probing
-h | --help Show this usage info -h | --help Show this usage info
EOF EOF
exit $1 exit $1
} }
@ -499,31 +499,25 @@ EOF
if [ $# -eq 1 ] && [ "$(echo $1 | cut -c 1)" != '-' ]; then if [ $# -eq 1 ] && [ "$(echo $1 | cut -c 1)" != '-' ]; then
INCLUDE="$1" INCLUDE="$1"
else else
while true; do while [ "$#" -gt 0 ]; do
case "$1" in case "$1" in
--include_dir) --include_dir)
shift shift
INCLUDE="$1" INCLUDE="$1" ;;
[ "$#" -gt 0 ] && shift ;;
--libbpf_dir) --libbpf_dir)
shift shift
LIBBPF_DIR="$1" LIBBPF_DIR="$1" ;;
[ "$#" -gt 0 ] && shift ;;
--libbpf_force) --libbpf_force)
if [ "$2" != 'on' ] && [ "$2" != 'off' ]; then shift
usage 1 LIBBPF_FORCE="$1" ;;
fi
LIBBPF_FORCE=$2
shift 2 ;;
-h | --help) -h | --help)
usage 0 ;; usage 0 ;;
--*) --*)
shift ;; ;;
"")
break ;;
*) *)
usage 1 ;; usage 1 ;;
esac esac
[ "$#" -gt 0 ] && shift
done done
fi fi
@ -531,6 +525,11 @@ fi
if [ "${LIBBPF_DIR-unused}" != "unused" ]; then if [ "${LIBBPF_DIR-unused}" != "unused" ]; then
[ -d "$LIBBPF_DIR" ] || usage 1 [ -d "$LIBBPF_DIR" ] || usage 1
fi fi
if [ "${LIBBPF_FORCE-unused}" != "unused" ]; then
if [ "$LIBBPF_FORCE" != 'on' ] && [ "$LIBBPF_FORCE" != 'off' ]; then
usage 1
fi
fi
echo "# Generated config based on" $INCLUDE >$CONFIG echo "# Generated config based on" $INCLUDE >$CONFIG
quiet_config >> $CONFIG quiet_config >> $CONFIG