Skip to contentSkip to conversation

configure: add options ability

PATCH In review Hangbin Liu 2 participants 2 messages May 28, 2021 – May 29, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: add options ability

From: Hangbin Liu <[email protected]>

Hi David,

As we talked in my previous libbpf support patchset. You'd like to make configure with option settings. Here is a draft patch. Not sure if this is what you want.

There are also a lot variables that I not sure if we should add options for them. e.g. PKG_CONFIG, CC, IPTC, IPT_LIB_DIR, etc. Do you have any suggestions?

---
As there are more and more global environment variables in configures. it would be more clear with options for users. Add related options for variables. Keep using the same name so the old way (set global env) is still working.

---
 configure | 45 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 6 deletions(-)
configure +39 -6
index 179eae08..aae324c9 100755
@@ -1,13 +1,8 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
 # This is not an autoconf generated configure
-#
-# Influential LIBBPF environment variables:
-#   LIBBPF_FORCE={on,off}   on: require link against libbpf;
-#                           off: disable libbpf probing
-#   LIBBPF_DIR              Path to libbpf DESTDIR to use
 
-INCLUDE=${1:-"$PWD/include"}
+INCLUDE="$PWD/include"
 
 # Output file which is input to Makefile
 CONFIG=config.mk
@@ -486,6 +481,44 @@ endif
 EOF
 }
 
+usage()
+{
+        cat <<EOF
+Usage: $0 [OPTIONS]
+  --libbpf_force                enable/disable libbpf by force.
+                                on: require link against libbpf, quite config if no libbpf support
+                                off: disable libbpf probing
+  --libbpf_dir                  Path to libbpf DESTDIR to use
+  --include_dir                 Path to iproute2 include dir
+  -h | --help                   Show this usage info
+EOF
+        exit $1
+}
+
+while true; do
+	case "$1" in
+		--libbpf_force)
+			if [ "$2" != 'on' ] && [ "$2" != 'off' ]; then
+				usage 1
+			fi
+			LIBBPF_FORCE=$2
+			shift 2 ;;
+                --libbpf_dir)
+			LIBBPF_DIR="$2"
+                        shift 2 ;;
+                --include_dir)
+			# How to deal with the old INCLUDE usage?
+			INCLUDE=$2
+                        shift 2 ;;
+                -h | --help)
+                        usage 0 ;;
+                "")
+                        break ;;
+                *)
+                        usage 1 ;;
+        esac
+done
+
 echo "# Generated config based on" $INCLUDE >$CONFIG
 quiet_config >> $CONFIG
 
Signature · 1 line
2.26.3
#1 lore raw
Quoted 11 lines · Hangbin Liu

From: Hangbin Liu <[email protected]>

Hi David,

As we talked in my previous libbpf support patchset. You'd like to make configure with option settings. Here is a draft patch. Not sure if this is what you want.

There are also a lot variables that I not sure if we should add options for them. e.g. PKG_CONFIG, CC, IPTC, IPT_LIB_DIR, etc. Do you have any suggestions?

I think it is better to have command line options vs environment variables. Command line options can be used with a usage / help function to make it easier for users to learn or remember the config options.

That said, the environment variable approach should continue to work for existing build scripts.

Your RFC looks fine to me. It would be easier to review if options are converted with separate patches vs one big one.

configure endif · line 510

Quoted 13 lines
configure +13 -0
+while true; do
+	case "$1" in
+		--libbpf_force)
+			if [ "$2" != 'on' ] && [ "$2" != 'off' ]; then
+				usage 1
+			fi
+			LIBBPF_FORCE=$2
+			shift 2 ;;
+                --libbpf_dir)
+			LIBBPF_DIR="$2"
+                        shift 2 ;;
+                --include_dir)
+			# How to deal with the old INCLUDE usage?

if number of input arguments is just 1 and it does not start with '-', then guess that it is old style INCLUDE.

Thanks for working on this.