665ce73
From e563a97894c173dcfe2ccdb061c9bfe16526678b Mon Sep 17 00:00:00 2001
665ce73
Message-Id: <e563a97894c173dcfe2ccdb061c9bfe16526678b.1634733799.git.aclaudi@redhat.com>
665ce73
In-Reply-To: <5e6e93a55d2335b90aacb0107e962610cce64007.1634733799.git.aclaudi@redhat.com>
665ce73
References: <5e6e93a55d2335b90aacb0107e962610cce64007.1634733799.git.aclaudi@redhat.com>
665ce73
From: Andrea Claudi <aclaudi@redhat.com>
665ce73
Date: Wed, 20 Oct 2021 12:32:38 +0200
665ce73
Subject: [PATCH] configure: simplify options parsing
665ce73
665ce73
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1999860
665ce73
Upstream Status: iproute2-next.git commit 99245d17
665ce73
665ce73
commit 99245d1741a85e4397973782578d4a78673eb348
665ce73
Author: Andrea Claudi <aclaudi@redhat.com>
665ce73
Date:   Thu Oct 14 10:50:52 2021 +0200
665ce73
665ce73
    configure: simplify options parsing
665ce73
665ce73
    This commit simplifies options parsing moving all the code not related to
665ce73
    parsing out of the case statement.
665ce73
665ce73
    - The conditional shift after the assignments is moved right after the
665ce73
      case, reducing code duplication.
665ce73
    - The semantic checks on the LIBBPF_FORCE value is moved after the loop
665ce73
      like we already did for INCLUDE and LIBBPF_DIR.
665ce73
    - Finally, the loop condition is changed to check remaining arguments, thus
665ce73
      making it possible to get rid of the null string case break.
665ce73
665ce73
    As a bonus, now the help message states that on or off should follow
665ce73
    --libbpf_force
665ce73
665ce73
    Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
665ce73
    Acked-by: Phil Sutter <phil@nwl.cc>
665ce73
    Signed-off-by: David Ahern <dsahern@kernel.org>
665ce73
---
665ce73
 configure | 37 ++++++++++++++++++-------------------
665ce73
 1 file changed, 18 insertions(+), 19 deletions(-)
665ce73
665ce73
diff --git a/configure b/configure
665ce73
index 9ec19a5b..26e06eb8 100755
665ce73
--- a/configure
665ce73
+++ b/configure
665ce73
@@ -485,12 +485,12 @@ usage()
665ce73
 {
665ce73
 	cat <
665ce73
 Usage: $0 [OPTIONS]
665ce73
-	--include_dir <dir>	Path to iproute2 include dir
665ce73
-	--libbpf_dir <dir>	Path to libbpf DESTDIR
665ce73
-	--libbpf_force		Enable/disable libbpf by force. Available options:
665ce73
-				  on: require link against libbpf, quit config if no libbpf support
665ce73
-				  off: disable libbpf probing
665ce73
-	-h | --help		Show this usage info
665ce73
+	--include_dir <dir>		Path to iproute2 include dir
665ce73
+	--libbpf_dir <dir>		Path to libbpf DESTDIR
665ce73
+	--libbpf_force <on|off>		Enable/disable libbpf by force. Available options:
665ce73
+					  on: require link against libbpf, quit config if no libbpf support
665ce73
+					  off: disable libbpf probing
665ce73
+	-h | --help			Show this usage info
665ce73
 EOF
665ce73
 	exit $1
665ce73
 }
665ce73
@@ -499,31 +499,25 @@ EOF
665ce73
 if [ $# -eq 1 ] && [ "$(echo $1 | cut -c 1)" != '-' ]; then
665ce73
 	INCLUDE="$1"
665ce73
 else
665ce73
-	while true; do
665ce73
+	while [ "$#" -gt 0 ]; do
665ce73
 		case "$1" in
665ce73
 			--include_dir)
665ce73
 				shift
665ce73
-				INCLUDE="$1"
665ce73
-				[ "$#" -gt 0 ] && shift ;;
665ce73
+				INCLUDE="$1" ;;
665ce73
 			--libbpf_dir)
665ce73
 				shift
665ce73
-				LIBBPF_DIR="$1"
665ce73
-				[ "$#" -gt 0 ] && shift ;;
665ce73
+				LIBBPF_DIR="$1" ;;
665ce73
 			--libbpf_force)
665ce73
-				if [ "$2" != 'on' ] && [ "$2" != 'off' ]; then
665ce73
-					usage 1
665ce73
-				fi
665ce73
-				LIBBPF_FORCE=$2
665ce73
-				shift 2 ;;
665ce73
+				shift
665ce73
+				LIBBPF_FORCE="$1" ;;
665ce73
 			-h | --help)
665ce73
 				usage 0 ;;
665ce73
 			--*)
665ce73
-				shift ;;
665ce73
-			"")
665ce73
-				break ;;
665ce73
+				;;
665ce73
 			*)
665ce73
 				usage 1 ;;
665ce73
 		esac
665ce73
+		[ "$#" -gt 0 ] && shift
665ce73
 	done
665ce73
 fi
665ce73
 
665ce73
@@ -531,6 +525,11 @@ fi
665ce73
 if [ "${LIBBPF_DIR-unused}" != "unused" ]; then
665ce73
 	[ -d "$LIBBPF_DIR" ] || usage 1
665ce73
 fi
665ce73
+if [ "${LIBBPF_FORCE-unused}" != "unused" ]; then
665ce73
+	if [ "$LIBBPF_FORCE" != 'on' ] && [ "$LIBBPF_FORCE" != 'off' ]; then
665ce73
+		usage 1
665ce73
+	fi
665ce73
+fi
665ce73
 
665ce73
 echo "# Generated config based on" $INCLUDE >$CONFIG
665ce73
 quiet_config >> $CONFIG
665ce73
-- 
665ce73
2.31.1
665ce73