diff options
Diffstat (limited to 'configure')
-rwxr-xr-x | configure | 237 |
1 files changed, 188 insertions, 49 deletions
@@ -7,92 +7,231 @@ set -eu +# Get the relative path to the source tree based on how the script was run +DIR=$(dirname -- "$0") + +# Print the help message help() { cat <<EOF -Usage: $0 [-j<N>] [CC=...] [CFLAGS=...] [...] +Usage: + + \$ $0 [--enable-*|--disable-*] [--with-*|--without-*] [CC=...] [...] + \$ $MAKE -j$(_nproc) -Compiler configuration: +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 - C preprocessor flags - CFLAGS - C compiler flags - LDFLAGS - Linker flags - LDLIBS + + CPPFLAGS="-I... -D..." + CFLAGS="-W... -f..." + LDFLAGS="-L... -Wl,..." + Preprocessor/compiler/linker flags + + LDLIBS="-l... -l..." Dynamic libraries to link - EXTRA_CPPFLAGS - EXTRA_CFLAGS - EXTRA_LDFLAGS - EXTRA_LDLIBS + EXTRA_{CPPFLAGS,CFLAGS,LDFLAGS,LDLIBS} Adds to the default flags, instead of replacing them -Build profiles: +The default flags result in a plain debug build. Other build profiles include: - RELEASE=y + --enable-release Enable optimizations, disable assertions - ASAN=y - LSAN=y - MSAN=y - TSAN=y - UBSAN=y + --enable-{asan,lsan,msan,tsan,tysan,ubsan} Enable sanitizers - GCOV=y + --enable-gcov Enable code coverage instrumentation -External dependencies: - - PKG_CONFIG - The pkg-config binary to use +External dependencies are auto-detected by default, but you can build --with or +--without them explicitly: - USE_LIBACL=[y|n] - USE_LIBCAP=[y|n] - USE_LIBSELINUX=[y|n] - USE_LIBURIG=[y|n] - USE_ONIGURUMA=[y|n] - Enable or disable external dependencies + --with-libacl --without-libacl + --with-libcap --without-libcap + --with-libselinux --without-libselinux + --with-liburing --without-liburing + --with-oniguruma --without-oniguruma -Packaging configuration: +Packaging: - PREFIX + --prefix=/path Set the installation prefix (default: /usr) - MANDIR + --mandir=/path Set the man page directory (default: \$PREFIX/share/man) + --version=X.Y.Z + Set the version string (default: $("$DIR/build/version.sh")) + +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$(_nproc) V=1 EOF } +# Report a warning +warn() { + fmt="$1" + shift + printf "%s: warning: $fmt\\n" "$0" "$@" >&2 +} + +# Report an argument parsing error +invalid() { + printf '%s: error: Unrecognized option "%s"\n\n' "$0" "$1" >&2 + printf 'Run %s --help for more information.\n' "$0" >&2 + exit 1 +} + +# Get the number of cores to use +_nproc() { + { + nproc \ + || sysctl -n hw.ncpu \ + || getconf _NPROCESSORS_ONLN \ + || echo 1 + } 2>/dev/null +} + +# Save the ./configure command line for bfs --version +export CONFFLAGS="" + +# Default to `make` +MAKE="${MAKE-make}" + +# Parse the command-line arguments for arg; do + shift + + # Only add --options to CONFFLAGS, so we don't print FLAG=values twice in bfs --version + case "$arg" in + -*) + CONFFLAGS="${CONFFLAGS}${CONFFLAGS:+ }${arg}" + ;; + esac + + # --[(enable|disable|with|without)-]$name[=$value] + value="${arg#*=}" + name="${arg%%=*}" + name="${name#--}" + case "$arg" in + --enable-*|--disable-*|--with-*|--without-*) + name="${name#*-}" + ;; + esac + NAME=$(printf '%s' "$name" | tr 'a-z-' 'A-Z_') + + # y/n modality + case "$arg" in + --enable-*|--with-*) + case "$arg" in + *=y|*=yes) yn=y ;; + *=n|*=no) yn=n ;; + *=*) invalid "$arg" ;; + *) yn=y ;; + esac + ;; + --disable-*|--without-*) + case "$arg" in + *=*) invalid "arg" ;; + *) yn=n ;; + esac + ;; + esac + + # Fix up --enable-lib* to --with-lib* + case "$arg" in + --enable-*|--disable-*) + case "$name" in + libacl|libcap|libselinux|liburing|oniguruma) + old="$arg" + case "$arg" in + --enable-*) arg="--with-${arg#--*-}" ;; + --disable-*) arg="--without-${arg#--*-}" ;; + esac + warn 'Treating "%s" like "%s"' "$old" "$arg" + ;; + esac + ;; + esac + case "$arg" in - --help) + -h|--help) help exit 0 ;; + + --enable-*|--disable-*) + case "$name" in + release|lto|asan|lsan|msan|tsan|tysan|ubsan|lint|gcov) + set -- "$@" "$NAME=$yn" + ;; + *) + invalid "$arg" + ;; + esac + ;; + + --with-*|--without-*) + case "$name" in + libacl|libcap|libselinux|liburing|oniguruma) + set -- "$@" "WITH_$NAME=$yn" + ;; + *) + invalid "$arg" + ;; + esac + ;; + + --prefix=*|--mandir=*|--version=*) + set -- "$@" "$NAME=$value" + ;; + + --infodir=*|--build=*|--host=*|--target=*) + warn 'Ignoring option "%s"' "$arg" + ;; + + MAKE=*) + MAKE="$value" + ;; + + # Warn about MAKE variables that have documented configure flags + RELEASE=*|LTO=*|ASAN=*|LSAN=*|MSAN=*|TSAN=*|TYSAN=*|UBSAN=*|LINT=*|GCOV=*) + name=$(printf '%s' "$NAME" | tr 'A-Z_' 'a-z-') + warn '"%s" is deprecated; use --enable-%s' "$arg" "$name" + set -- "$@" "$arg" + ;; + + PREFIX=*|MANDIR=*|VERSION=*) + name=$(printf '%s' "$NAME" | tr 'A-Z_' 'a-z-') + warn '"%s" is deprecated; use --%s=%s' "$arg" "$name" "$value" + set -- "$@" "$arg" + ;; + + WITH_*=*) + name=$(printf '%s' "$NAME" | tr 'A-Z_' 'a-z-') + warn '"%s" is deprecated; use --%s' "$arg" "$name" + set -- "$@" "$arg" + ;; + + # make flag (-j2) or variable (CC=clang) -*|*=*) - continue # make flag (-j2) or variable (CC=clang) + set -- "$@" "$arg" ;; + *) - printf 'error: Unrecognized option "%s"\n\n' "$arg" >&2 - help >&2 - exit 1 + invalid "$arg" ;; esac done -# Get the relative path to the source tree based on how the script was run -DIR=$(dirname -- "$0") - # Set up symbolic links for out-of-tree builds -for f in Makefile build completions docs src tests; do +for f in Makefile bench build completions docs src tests; do test -e "$f" || ln -s "$DIR/$f" "$f" done -# Infer -jN unless MAKEFLAGS is set -j= -if ! [ "${MAKEFLAGS+y}" ]; then - j="-j$({ nproc || sysctl -n hw.ncpu || getconf _NPROCESSORS_ONLN || echo 1; } 2>/dev/null)" -fi +# Set MAKEFLAGS to -j$(_nproc) if it's unset +export MAKEFLAGS="${MAKEFLAGS--j$(_nproc)}" -${MAKE:-make} $j -rsf build/config.mk "$@" +$MAKE -rf build/config.mk "$@" |