diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-04-08 11:27:11 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-04-09 17:15:23 -0400 |
commit | c31577d102d87455f3f12086be4c0e2159fa5d35 (patch) | |
tree | 864c7c199e5b846dcf497de8b667d6c6f8c550b9 /config/pkgconf.sh | |
parent | 5e0b721d0d929223e4308406480a1f1ca9e3f4dc (diff) | |
download | bfs-c31577d102d87455f3f12086be4c0e2159fa5d35.tar.xz |
build: Add a separate configuration step
Diffstat (limited to 'config/pkgconf.sh')
-rwxr-xr-x | config/pkgconf.sh | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/config/pkgconf.sh b/config/pkgconf.sh new file mode 100755 index 0000000..070fad6 --- /dev/null +++ b/config/pkgconf.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# Copyright © Tavian Barnes <tavianator@tavianator.com> +# SPDX-License-Identifier: 0BSD + +# pkg-config wrapper with hardcoded fallbacks + +set -eu + +MODE= +if [[ "$1" == --* ]]; then + MODE="$1" + shift +fi + +if command -v "${PKG_CONFIG:-}" &>/dev/null; then + case "$MODE" in + --cflags) + "$PKG_CONFIG" --cflags "$@" + ;; + --ldflags) + "$PKG_CONFIG" --libs-only-L --libs-only-other "$@" + ;; + --ldlibs) + "$PKG_CONFIG" --libs-only-l "$@" + ;; + "") + "$PKG_CONFIG" "$@" + ;; + esac +else + for lib; do + case "$lib" in + libacl) + LDLIB=-lacl + ;; + libcap) + LDLIB=-lcap + ;; + liburing) + LDLIB=-luring + ;; + oniguruma) + LDLIB=-lonig + ;; + *) + printf 'error: Unknown package %s\n' "$lib" >&2 + exit 1 + esac + + case "$MODE" in + --ldlibs) + printf ' %s' "$LDLIB" + ;; + "") + config/cc.sh "config/$lib.c" "$LDLIB" || exit $? + ;; + esac + done + + if [ "$MODE" = "--ldlibs" ]; then + printf '\n' + fi +fi |