summaryrefslogtreecommitdiffstats
path: root/config/pkg.sh
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-04-08 11:27:11 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-04-09 17:15:23 -0400
commitc31577d102d87455f3f12086be4c0e2159fa5d35 (patch)
tree864c7c199e5b846dcf497de8b667d6c6f8c550b9 /config/pkg.sh
parent5e0b721d0d929223e4308406480a1f1ca9e3f4dc (diff)
downloadbfs-c31577d102d87455f3f12086be4c0e2159fa5d35.tar.xz
build: Add a separate configuration step
Diffstat (limited to 'config/pkg.sh')
-rwxr-xr-xconfig/pkg.sh44
1 files changed, 44 insertions, 0 deletions
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