summaryrefslogtreecommitdiffstats
path: root/configure
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-06-18 16:54:13 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-06-18 16:58:22 -0400
commit49a5d48d0a43bac313c8b8d1b167e60da9eaadf6 (patch)
tree91ad35a950e27e1af58cba376f3ad1049f0dea6c /configure
parenta7ef73a406b46ec226014afdb6a099c3ea96230f (diff)
downloadbfs-49a5d48d0a43bac313c8b8d1b167e60da9eaadf6.tar.xz
configure: Fix VAR=value before --option
Previously we were not shifting all arguments, leading to $ ./configure CC=gcc --enable-release make: unrecognized option '--enable-release' as the loop would shift the CC=gcc argument instead of --enable-release.
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure153
1 files changed, 77 insertions, 76 deletions
diff --git a/configure b/configure
index 40eb313..bed7df2 100755
--- a/configure
+++ b/configure
@@ -7,22 +7,62 @@
set -eu
-# Save the ./configure command line for bfs --version
-export CONFIG="$0 $*"
+# Print the help message()
+help() {
+ cat <<EOF
+Usage:
-# Default to `make`
-MAKE="${MAKE:-make}"
-
-# Pass -j$(nproc) unless MAKEFLAGS is set
-if [ "${MAKEFLAGS+y}" ]; then
- j=""
-else
- j="-j$({ nproc || sysctl -n hw.ncpu || getconf _NPROCESSORS_ONLN || echo 1; } 2>/dev/null)"
-fi
-
-# Convert kebab-case to UPPER_CASE
-toupper() {
- printf '%s' "$1" | tr 'a-z-' 'A-Z_'
+ \$ $0 [--enable-*|--disable-*] [--with-*|--without-*] [CC=...] [...]
+ \$ $MAKE $j
+
+Variables set in the environment or on the command line will be picked up:
+
+ MAKE
+ The make implementation to use
+ CC
+ The C compiler to use
+
+ CPPFLAGS="-I... -D..."
+ CFLAGS="-W... -f..."
+ LDFLAGS="-L... -Wl,..."
+ Preprocessor/compiler/linker flags
+
+ LDLIBS="-l... -l..."
+ Dynamic libraries to link
+
+ EXTRA_{CPPFLAGS,CFLAGS,LDFLAGS,LDLIBS}
+ Adds to the default flags, instead of replacing them
+
+The default flags result in a plain debug build. Other build profiles include:
+
+ --enable-release
+ Enable optimizations, disable assertions
+ --enable-{asan,lsan,msan,tsan,ubsan}
+ Enable sanitizers
+ --enable-gcov
+ Enable code coverage instrumentation
+
+External dependencies are auto-detected by default, but you can build --with or
+--without them explicitly:
+
+ --with-libacl --without-libacl
+ --with-libcap --without-libcap
+ --with-libselinux --without-libselinux
+ --with-liburing --without-liburing
+ --with-oniguruma --without-oniguruma
+
+Packaging:
+
+ --prefix=/path
+ Set the installation prefix (default: /usr)
+ --mandir=/path
+ Set the man page directory (default: \$PREFIX/share/man)
+
+This script is a thin wrapper around a makefile-based configuration system.
+Any other arguments will be passed directly to the $MAKE invocation, e.g.
+
+ \$ $0 $j V=1
+EOF
}
# Report an argument parsing error
@@ -32,7 +72,26 @@ invalid() {
exit 1
}
+# Get the number of cores to use
+nproc() {
+ {
+ command nproc \
+ || sysctl -n hw.ncpu \
+ || getconf _NPROCESSORS_ONLN \
+ || echo 1
+ } 2>/dev/null
+}
+
+# Save the ./configure command line for bfs --version
+export CONFIG="$0 $*"
+
+# Default to `make`
+MAKE="${MAKE-make}"
+
+# Parse the command-line arguments
for arg; do
+ shift
+
# --[(enable|disable|with|without)-]$name[=$value]
value="${arg#*=}"
name="${arg%%=*}"
@@ -80,67 +139,13 @@ for arg; do
case "$arg" in
-h|--help)
- cat <<EOF
-Usage:
-
- \$ $0 [--enable-*|--disable-*] [--with-*|--without-*] [CC=...] [...]
- \$ $MAKE $j
-
-Variables set in the environment or on the command line will be picked up:
-
- MAKE
- The make implementation to use
- CC
- The C compiler to use
-
- CPPFLAGS="-I... -D..."
- CFLAGS="-W... -f..."
- LDFLAGS="-L... -Wl,..."
- Preprocessor/compiler/linker flags
-
- LDLIBS="-l... -l..."
- Dynamic libraries to link
-
- EXTRA_{CPPFLAGS,CFLAGS,LDFLAGS,LDLIBS}
- Adds to the default flags, instead of replacing them
-
-The default flags result in a plain debug build. Other build profiles include:
-
- --enable-release
- Enable optimizations, disable assertions
- --enable-{asan,lsan,msan,tsan,ubsan}
- Enable sanitizers
- --enable-gcov
- Enable code coverage instrumentation
-
-External dependencies are auto-detected by default, but you can build --with or
---without them explicitly:
-
- --with-libacl --without-libacl
- --with-libcap --without-libcap
- --with-libselinux --without-libselinux
- --with-liburing --without-liburing
- --with-oniguruma --without-oniguruma
-
-Packaging:
-
- --prefix=/path
- Set the installation prefix (default: /usr)
- --mandir=/path
- Set the man page directory (default: \$PREFIX/share/man)
-
-This script is a thin wrapper around a makefile-based configuration system.
-Any other arguments will be passed directly to the $MAKE invocation, e.g.
-
- \$ $0 $j V=1
-EOF
+ help
exit 0
;;
--enable-*|--disable-*)
case "$name" in
release|asan|lsan|msan|tsan|ubsan|lint|gcov)
- shift
set -- "$@" "$NAME=$yn"
;;
*)
@@ -152,7 +157,6 @@ EOF
--with-*|--without-*)
case "$name" in
libacl|libcap|libselinux|liburing|oniguruma)
- shift
set -- "$@" "WITH_$NAME=$yn"
;;
*)
@@ -162,23 +166,20 @@ EOF
;;
--prefix=*|--mandir=*)
- shift
set -- "$@" "$NAME=$value"
;;
--infodir=*|--build=*|--host=*|--target=*)
- shift
printf 'warning: Ignoring option "%s"\n' "$arg" >&2
;;
MAKE=*)
- shift
MAKE="$value"
;;
# make flag (-j2) or variable (CC=clang)
-*|*=*)
- continue
+ set -- "$@" "$arg"
;;
*)
@@ -196,6 +197,6 @@ for f in Makefile build completions docs src tests; do
done
# Set MAKEFLAGS to -j$(nproc) if it's unset
-export MAKEFLAGS="${MAKEFLAGS-$j}"
+export MAKEFLAGS="${MAKEFLAGS--j$(nproc)}"
$MAKE -rf build/config.mk "$@"