#!/bin/sh # Copyright © Tavian Barnes # SPDX-License-Identifier: 0BSD # bfs build configuration script set -eu # Save the ./configure command line for bfs --version export CONFIG="$0 $*" # 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_' } # Report an argument parsing error invalid() { printf 'error: Unrecognized option "%s"\n\n' "$1" >&2 printf 'Run %s --help for more information.\n' "$0" >&2 exit 1 } for arg; do # --[(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 printf 'warning: Treating "%s" like "%s"\n' "$old" "$arg" >&2 ;; esac ;; esac case "$arg" in -h|--help) cat <&2 ;; MAKE=*) shift MAKE="$value" ;; # make flag (-j2) or variable (CC=clang) -*|*=*) continue ;; *) 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 test -e "$f" || ln -s "$DIR/$f" "$f" done # Set MAKEFLAGS to -j$(nproc) if it's unset export MAKEFLAGS="${MAKEFLAGS-$j}" $MAKE -rf build/config.mk "$@"