From d7d5e1c474e4e110172b7180de9c41e5ebbf93f6 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 18 Apr 2024 16:16:36 -0400 Subject: config: Test-compile packages even if pkg-config says they exist This fixes `make config CC=musl-gcc`, for example. --- config/pkgconf.sh | 104 +++++++++++++++++++++++++++--------------------------- config/pkgs.mk | 6 ++-- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/config/pkgconf.sh b/config/pkgconf.sh index d6c45c7..2dbad76 100755 --- a/config/pkgconf.sh +++ b/config/pkgconf.sh @@ -23,66 +23,66 @@ case "$XNOLIBS" in exit 1 esac +if [ -z "$MODE" ]; then + # Check whether the libraries exist at all + for LIB; do + CFLAGS=$("$0" --cflags "$LIB") || exit 1 + LDFLAGS=$("$0" --ldflags "$LIB") || exit 1 + LDLIBS=$("$0" --ldlibs "$LIB") || exit 1 + config/cc.sh $CFLAGS $LDFLAGS config/$LIB.c $LDLIBS || exit 1 + done +fi + +# Defer to pkg-config if possible if command -v "${XPKG_CONFIG:-}" >/dev/null 2>&1; then case "$MODE" in - "") - "$XPKG_CONFIG" "$@" - ;; --cflags) - OUT=$("$XPKG_CONFIG" --cflags "$@") - if [ "$OUT" ]; then - printf 'CFLAGS += %s\n' "$OUT" - fi + "$XPKG_CONFIG" --cflags "$@" ;; --ldflags) - OUT=$("$XPKG_CONFIG" --libs-only-L --libs-only-other "$@") - if [ "$OUT" ]; then - printf 'LDFLAGS += %s\n' "$OUT" - fi + "$XPKG_CONFIG" --libs-only-L --libs-only-other "$@" ;; --ldlibs) - OUT=$("$XPKG_CONFIG" --libs-only-l "$@") - if [ "$OUT" ]; then - printf 'LDLIBS := %s ${LDLIBS}\n' "$OUT" - fi + "$XPKG_CONFIG" --libs-only-l "$@" ;; esac -else - LDLIBS="" - for LIB; do - case "$LIB" in - libacl) - LDLIB=-lacl - ;; - libcap) - LDLIB=-lcap - ;; - libselinux) - LDLIB=-lselinux - ;; - liburing) - LDLIB=-luring - ;; - oniguruma) - LDLIB=-lonig - ;; - *) - printf 'error: Unknown package %s\n' "$LIB" >&2 - exit 1 - ;; - esac - case "$MODE" in - "") - config/cc.sh "config/$LIB.c" "$LDLIB" || exit $? - ;; - --ldlibs) - LDLIBS="$LDLIBS $LDLIB" - ;; - esac - done - - if [ "$MODE" = "--ldlibs" ] && [ "$LDLIBS" ]; then - printf 'LDLIBS :=%s ${LDLIBS}\n' "$LDLIBS" - fi + exit fi + +# pkg-config unavailable, emulate it ourselves +CFLAGS="" +LDFLAGS="" +LDLIBS="" + +for LIB; do + case "$LIB" in + libacl) + LDLIB=-lacl + ;; + libcap) + LDLIB=-lcap + ;; + libselinux) + LDLIB=-lselinux + ;; + liburing) + LDLIB=-luring + ;; + oniguruma) + LDLIB=-lonig + ;; + *) + printf 'error: Unknown package %s\n' "$LIB" >&2 + exit 1 + ;; + esac + + LDLIBS="$LDLIBS$LDLIB " +done + +case "$MODE" in + --ldlibs) + printf '%s\n' "$LDLIBS" + ;; +esac diff --git a/config/pkgs.mk b/config/pkgs.mk index de9e16e..3a18289 100644 --- a/config/pkgs.mk +++ b/config/pkgs.mk @@ -11,7 +11,7 @@ include config/exports.mk ${GEN}/pkgs.mk:: ${MSG} "[ GEN] ${TGT}" - config/pkgconf.sh --cflags ${PKGS} >>$@ 2>>$@.log - config/pkgconf.sh --ldflags ${PKGS} >>$@ 2>>$@.log - config/pkgconf.sh --ldlibs ${PKGS} >>$@ 2>>$@.log + printf 'CFLAGS += %s\n' "$$(config/pkgconf.sh --cflags ${PKGS})" >>$@ 2>>$@.log + printf 'LDFLAGS += %s\n' "$$(config/pkgconf.sh --ldflags ${PKGS})" >>$@ 2>>$@.log + printf 'LDLIBS := %s $${LDLIBS}\n' "$$(config/pkgconf.sh --ldlibs ${PKGS})" >>$@ 2>>$@.log ${VCAT} $@ -- cgit v1.2.3