summaryrefslogtreecommitdiffstats
path: root/config/pkgconf.sh
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-04-10 13:13:19 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-04-10 13:23:40 -0400
commit6c8d11e8e5b3457286fcda75b6516e93f1f12f17 (patch)
treeb637ba7322df4e60e4e8174f53b48348b8f408a1 /config/pkgconf.sh
parent8f5ce115d51d31756b6911310a0deb1bafba46c0 (diff)
downloadbfs-6c8d11e8e5b3457286fcda75b6516e93f1f12f17.tar.xz
build: Run pkg-config with all packages at once
Diffstat (limited to 'config/pkgconf.sh')
-rwxr-xr-xconfig/pkgconf.sh51
1 files changed, 35 insertions, 16 deletions
diff --git a/config/pkgconf.sh b/config/pkgconf.sh
index 286c19c..a13b30f 100755
--- a/config/pkgconf.sh
+++ b/config/pkgconf.sh
@@ -8,29 +8,47 @@
set -eu
MODE=
-if [[ "$1" == --* ]]; then
+if [[ "${1:-}" == --* ]]; then
MODE="$1"
shift
fi
+if (($# < 1)); then
+ exit
+fi
+
+if [[ "$NOLIBS" == *y* ]]; then
+ exit 1
+fi
+
if command -v "${PKG_CONFIG:-}" &>/dev/null; then
case "$MODE" in
+ "")
+ "$PKG_CONFIG" "$@"
+ ;;
--cflags)
- "$PKG_CONFIG" --cflags "$@"
+ OUT=$("$PKG_CONFIG" --cflags "$@")
+ if [ "$OUT" ]; then
+ printf 'CFLAGS += %s\n' "$OUT"
+ fi
;;
--ldflags)
- "$PKG_CONFIG" --libs-only-L --libs-only-other "$@"
+ OUT=$("$PKG_CONFIG" --libs-only-L --libs-only-other "$@")
+ if [ "$OUT" ]; then
+ printf 'LDFLAGS += %s\n' "$OUT"
+ fi
;;
--ldlibs)
- "$PKG_CONFIG" --libs-only-l "$@"
- ;;
- "")
- "$PKG_CONFIG" "$@"
+ OUT=$("$PKG_CONFIG" --libs-only-l "$@")
+ if [ "$OUT" ]; then
+ printf 'LDLIBS := %s ${LDLIBS}\n' "$OUT"
+ fi
;;
esac
else
- for lib; do
- case "$lib" in
+ LDLIBS=""
+ for LIB; do
+ case "$LIB" in
libacl)
LDLIB=-lacl
;;
@@ -47,21 +65,22 @@ else
LDLIB=-lonig
;;
*)
- printf 'error: Unknown package %s\n' "$lib" >&2
+ 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 $?
+ config/cc.sh "config/$LIB.c" "$LDLIB" || exit $?
+ ;;
+ --ldlibs)
+ LDLIBS="$LDLIBS $LDLIB"
;;
esac
done
- if [ "$MODE" = "--ldlibs" ]; then
- printf '\n'
+ if [ "$MODE" = "--ldlibs" ] && [ "$LDLIBS" ]; then
+ printf 'LDLIBS :=%s ${LDLIBS}\n' "$LDLIBS"
fi
fi