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 | |
parent | 5e0b721d0d929223e4308406480a1f1ca9e3f4dc (diff) | |
download | bfs-c31577d102d87455f3f12086be4c0e2159fa5d35.tar.xz |
build: Add a separate configuration step
Diffstat (limited to 'config')
-rwxr-xr-x | config/cc.sh | 12 | ||||
-rw-r--r-- | config/empty.c | 6 | ||||
-rw-r--r-- | config/libacl.c | 6 | ||||
-rw-r--r-- | config/libcap.c | 6 | ||||
-rw-r--r-- | config/liburing.c | 6 | ||||
-rw-r--r-- | config/oniguruma.c | 6 | ||||
-rwxr-xr-x | config/pkg.sh | 44 | ||||
-rwxr-xr-x | config/pkgconf.sh | 64 |
8 files changed, 150 insertions, 0 deletions
diff --git a/config/cc.sh b/config/cc.sh new file mode 100755 index 0000000..04b142a --- /dev/null +++ b/config/cc.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# Copyright © Tavian Barnes <tavianator@tavianator.com> +# SPDX-License-Identifier: 0BSD + +# Run the compiler and check if it succeeded + +printf '$ %s' "$XCC" >&2 +printf ' %q' "$@" >&2 +printf ' -o /dev/null\n' >&2 + +$XCC "$@" -o /dev/null diff --git a/config/empty.c b/config/empty.c new file mode 100644 index 0000000..4fa9a5b --- /dev/null +++ b/config/empty.c @@ -0,0 +1,6 @@ +// Copyright © Tavian Barnes <tavianator@tavianator.com> +// SPDX-License-Identifier: 0BSD + +int main(void) { + return 0; +} diff --git a/config/libacl.c b/config/libacl.c new file mode 100644 index 0000000..877cb69 --- /dev/null +++ b/config/libacl.c @@ -0,0 +1,6 @@ +#include <sys/acl.h> + +int main(void) { + acl_free(0); + return 0; +} diff --git a/config/libcap.c b/config/libcap.c new file mode 100644 index 0000000..64188ac --- /dev/null +++ b/config/libcap.c @@ -0,0 +1,6 @@ +#include <sys/capability.h> + +int main(void) { + cap_free(0); + return 0; +} diff --git a/config/liburing.c b/config/liburing.c new file mode 100644 index 0000000..456059c --- /dev/null +++ b/config/liburing.c @@ -0,0 +1,6 @@ +#include <liburing.h> + +int main(void) { + io_uring_free_probe(0); + return 0; +} diff --git a/config/oniguruma.c b/config/oniguruma.c new file mode 100644 index 0000000..b834fac --- /dev/null +++ b/config/oniguruma.c @@ -0,0 +1,6 @@ +#include <oniguruma.h> + +int main(void) { + onig_free(0); + return 0; +} diff --git a/config/pkg.sh b/config/pkg.sh new file mode 100755 index 0000000..6335b4b --- /dev/null +++ b/config/pkg.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +# Copyright © Tavian Barnes <tavianator@tavianator.com> +# SPDX-License-Identifier: 0BSD + +# pkg-config wrapper that outputs a makefile fragment + +set -eu + +NAME="${1^^}" +declare -n XUSE="XUSE_$NAME" + +if [ "$XUSE" ]; then + USE="$XUSE" +elif [[ "$NOLIBS" == *y* ]]; then + USE=n +elif config/pkgconf.sh "$1"; then + USE=y +else + USE=n +fi + +printf '%s := %s\n' "USE_$NAME" "$USE" + +if [ "$USE" = y ]; then + printf 'CPPFLAGS += -DBFS_USE_%s=1\n' "$NAME" + + CFLAGS=$(config/pkgconf.sh --cflags "$1") + if [ "$CFLAGS" ]; then + printf 'CFLAGS += %s\n' "$CFLAGS" + fi + + LDFLAGS=$(config/pkgconf.sh --ldflags "$1") + if [ "$LDFLAGS" ]; then + printf 'LDFLAGS += %s\n' "$LDFLAGS" + fi + + LDLIBS=$(config/pkgconf.sh --ldlibs "$1") + if [ "$LDLIBS" ]; then + printf 'LDLIBS += %s\n' "$LDLIBS" + fi +else + printf 'CPPFLAGS += -DBFS_USE_%s=0\n' "$NAME" +fi 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 |