#!/bin/sh # Copyright © Tavian Barnes # SPDX-License-Identifier: 0BSD # bfs build configuration script set -eu # 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 for arg; do case "$arg" in -h|--help) cat <&2 printf 'Run %s --help for more information.\n' "$0" >&2 exit 1 ;; esac ;; --prefix=*) shift set -- "$@" "PREFIX=${arg#*=}" ;; MAKE=*) MAKE="${arg#*=}" shift ;; # make flag (-j2) or variable (CC=clang) -*|*=*) continue ;; *) printf 'error: Unrecognized option "%s"\n\n' "$arg" >&2 printf 'Run %s --help for more information.\n' "$0" >&2 exit 1 ;; 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 "$@"